8: Model Execution

Follow

Execution Setup & Running the Model

Following on from processing the model and final checks, we can run the model in a number of ways.

Basic Model Execution:

The basic information required prior to executing the model:

  • Model timestep (step)
  • Simulation runtime (simtime)
  • Simulation runtime in terms of number of timesteps (nexec)
c runtime calculations
symb #get { step } timestep    	/* extract calculated timestep from prcs command 
symb simtime = 40 / $freqint   	/* simulation time - 40 cycles @ 1 mhz 
symb nexec = $simtime / $step  	/* determine how many timesteps to run full model

Once we have the total number of timesteps to run the simulation for, we can use the exec command to execute the model. Typically, we would set up plots for to visualise the simulated outputs too:

c running the model
exec $nexec    	/* execute model for 'nexec' timesteps

c plot outputs 
grph 
    nvew 3 1      /* set up 3 views for data plots
    plot ydsp     /* plot calculated data array
    plot pmax     /* plot max pressure data array
    plot 2        /* plot time history 2 - pressure signal at front of defect
    end
term    /* pause model to view results

20.PNG

Great! We ran our first simulation however, we may want to visualise data at points thoughout the model simulation for analysis/debugging purposes. We can improve on this method by using a do loop.

Improved Model Execution:

Additional variables are required for the do loop method of executing the model:

  • Number of do loop iterations(nloops)
  • Number of timestep executions per do loop iteration (nexec2)
c runtime calculations
symb #get { step } timestep    	/* extract calculated timestep from prcs command 
symb simtime = 40 / $freqint   	/* simulation time - 40 cycles @ 1 mhz 
symb nexec = $simtime / $step  	/* determine how many timesteps to run full model
symb nloops = 80               	/* plotting snapshots during model execution
symb nexec2 = $nexec / $nloops 	/* partition full simulation into smaller segments for plotting

The do loop will have to loop nloops times, and will have to execute the model for nexec2 timesteps before plotting the results to the interactive graphics window.

c setting up output plots
grph
    	arrow off  /* turn off arrows
    	line off   /* turn off mesh lines
    	nvew 3 1   /* set up 3 plotting windows in layout number 1
    	end

do loopi i 1 $nloops 1    	/* setting up do loop
exec $nexec2    	/* run model for 'nexec2' timesteps

grph 
    	plot ydsp  /* plot calculated data array
    	plot 1    	/* plot time history 1 - drive function
    	plot 3    	/* plot time history 3 - charge on top electrode
    	imag      	/* snapshot of graphics window for movie generation
    	end
end$ loopi
term    /* pause model to view results

The do loop is very simple to set up:

  1. Initiate the do command
  2. Assign the do loop with a name(loopi)
  3. Assign the do loop with a loop variable (i) i.e. to control how many loops to run for
  4. Define start and end value the loop variable(1 to $nloops)
  5. Define incremental value to step through from start to end value(1)

Place the exec and grph commands within the do loop and terminate the do loop using the end$ command followed by the name of the loop.

Tip: Always minimise the amount of execution code within a do loop or procedure for optimal runtime performance. Avoid placing grph setup commands within the execution loops such as nvew, mirr etc.

The do loop has allowed us to view the simulated results at interval stages of the model right through until the end of the simulation however, there may be situations where we haven't simulated the model for a long enough time period. In such cases, we would need to restart the model and increase the simtime variable and re-run the entire model again which is very inefficient. We can further improve the model execution process using a procedure.

Optimal Model Execution:

A procedure is a segment of code that can be recalled a number of times using the proc command. It is almost identical to how we have set up the do loop; we simply replace the do loop with the proc setup commands:

proc plot save  	/* setting up procedure with name 'plot
exec $nexec2    	/* run model for 'nexec2' timesteps

grph 
    plot ydsp  /* plot calculated data array
    plot 1    	/* plot time history 1 - drive function
    plot 3    	/* plot time history 3 - charge on top electrode
    imag      	/* snapshot of graphics window for movie generation
    end
end$ proc               /* end procedure 

proc plot $nloops	/* call 'plot' procedure 'nloops' times
term                    /* pause model to view results

So when the simulation reaches the term command now, the user can enter in the console input:

p> proc plot 10

which will execute procedure for an additional 10 times.

Tip: Always use a procedure to execute a model for greater control of your execution stage, should you ever need it.

Extracting Outputs

After the simulation has fully executed, we can ask the solver to output certain data calculated during the simulation to an output file (.flxdato) ready to be post-processed. Most commonly we extract: the model geometry, any of the calculated properties (pres aprs xdsp loss pmax etc.) and any requested mode shape data.

data	
    	out modl        	/* outputs model geometry
    	out pres        	/* outputs pressure data field at the final simulated timestep
    	out shap/all    	/* output all requested mode shape data 
    	end 

It is also good modelling practice to output all the symbol variables used in the model. This gives the user insight into settings used or perhaps to allow the variables to be read into a post processing script:

c save symbols to file for later use
symb #get { label } jobname         	/* get model job name
symb #save $label.symb        	/* save symbol file

c end of input file     
stop 

Finally, issue the stop command to exit the system process in an orderly fashion.

Tutorial Tasks

Within the PZT2D.flxinp file:

  1. Using the symb command:
    • Return the timestep to a variable (step) with the #get option
    • Set a variable (simtime) to 40 cycles at frequency of interest
    • Calculate and store the total number of timesteps to execute for (nexec)
    • Set the plotting loop variable nloops to 40
    • Calculate and store the timesteps per plotting loop(nexec2)
  2. Using the grph command:
    • Turn off poling arrow arrow subcommand
    • Turn off mesh lines with line subcommand
    • Set the imag option to avi with the set subcommand
    • Set up 3 views for the interactive graphics window using the nvew subcommand
    • Issue end command
  3. Initiate the plotting procedure with the proc command followed by the name (plot) of the procedure and save option
  4. Using the exec command run the model for nexec2 timesteps
  5. Using the grph command:
    • plot the Y-Displacement array (ydsp) and time history 1 and 3
    • Issue the imag command to save image frames for a video animation of the model execution
    • Issue end command
  6. Close the procedure code using the end$ following by the proc option
  7. To run the model use the proc command followed by the name of the procedure (plot) and the number of iterations (nloops)
  8. Always enter a term command to pause the model at this stage - allows you to run the model for longer if required
  9. Using the data command: output the model geometry (modl), pressure snapshot (pres) and all requested mode shape data (shap/all).
  10. Return the jobname with the symb #get option into a variable (label)
  11. symb #save the symbols used in with '$label.symb' filename
  12. Issue the final command to stop the system process in an orderly manner

Progress to the final section: Summary

Tutorial Code

c runtime calculations
symb #get { step } timestep    	/* extract calculated timestep from prcs command 
symb simtime = 40 / $freqint   	/* simulation time - 40 cycles @ 1 mhz 
symb nexec = $simtime / $step  	/* determine how many timesteps to run full model
symb nloops = 40               	/* plotting snapshots during model execution
symb nexec2 = $nexec / $nloops 	/* partition full simulation into smaller segments for plotting

c setting up output plots grph arrow off /* turn off arrows line off /* turn off mesh lines
set imag avi /* set image capture for movie file generation nvew 3 1 /* set up 3 plotting windows in layout number 1 end
c create procedure - code that can be executed 'x' number of times
proc plot save /* name procedure 'plot' and save the code

exec $nexec2 /* run model partially

grph

plot ydsp /* plot calculated data array
plot
1 /* plot time history 1 - drive function
plot
3 /* plot time history 3 - charge on top electrode
imag
/* snapshot of graphics window for movie generation
end

end$ proc /* end of procedure

c run model by calling 'plot' procedure 'nloops' times
proc plot $nloops
term
/* pause model to view results
data
out modl /* outputs model geometry
out pres /* outputs pressure data field at the final simulated timestep
out shap/all /* output all requested mode shape data
end


c save symbols to file for later use

symb #get
{ label } jobname /* get model job name
symb #save '$label.symb' /* save symbol file

c end of input file
stop
1 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.