Result Objects#
- class SimulationResults#
Container object that encloses all the results from a single simulation. This object enables you to retrieve output states for Bodies, Requests and Rvs for each output time step.
There are two ways to instruct msolve to store the simulation results. In the
Model.simulate
method, one of the following must be set:- onOutputStep
Function that is called when the solver hits an output step. It can be used for animation and live plots.
- returnResults
Boolean that if True, causes SimulationResults to be populated.
- asDataFrame(start=0, end=None)#
Returns the runData object as a dictionary of Pandas dataframes. The keys of the dictionary are the objects whose results are stored.
- Parameters:
start (float) – Start time value for trimming each DataFrame.
end (float) – End time value for trimming each DataFrame.
- Returns:
A new dictionary where each value is the result of the
ResultObject.getDataFrame
method called on the original value.
- getObject(obj)#
Extracts the specified results from the SimulationResults (run) container and passes them into a
ResultObject
object.- Parameters:
obj (Body, Request, Rv, Name) – The object whose results are to be retrieved, or the unique name given to the object.
- Returns:
The
ResultObject
that is associated to the obj.
Note
Using the object as a lookup key is useful, so you don’t have to know the name of the object. This approach allows for convenient lookups without relying on object names.
Using the name string as a lookup key is advantageous in scenarios such as plot templates or when working with serialized data in formats like pickle files. In such cases, the model instance and its associated objects may not be directly accessible, making the use of objects impractical. Using the name string allows for reliable lookups even when the object hierarchy is not available.
- class ResultObject#
Base class for all the result objects of a simulation. The methods of this class are the access point to the numerical data of the simulation results.
- getComponent(component)#
Queries a ResultObject and returns the time history of a specific component of the object. The components can be indexed with their index number or their respective label.
The available components for each object are listed in
BodyResult
,FlexBodyResult
,PointMassResult
,RequestResult
,RvResult
.
- getDataFrame()#
The entire ResultObject corresponding to the owner is returned as a Pandas DataFrame. It contains all the components and uses labels as column names.
Useful Pandas DataFrame functionalities:
- df.info()
Prints concise summary of the DataFrame.
- df.describe()
Generates descriptive statistics for all columns including min, std, max, mean.
- df[‘column_name’] or df.column_name
Returns the column with name ‘column_name’ as a pandas Series.
- df.columns
Prints a pandas index corresponding to all the columns.
- getStep(step=-1)#
Queries a ResultObject and returns all of its data for a specific time step, which is given as input.
- class BodyResult#
Contains all the results associated with a single Part of the model.
At each output time, the following results are stored:
Components
Label
Index
Local Part Reference Frame (LPRF) position
X, Y, Z
0 - 2
Euler parameters
E0, E1, E2, E3
3 - 6
Example
from msolve import * model = Model(output='body_results') Units(system='MKS') Accgrav(kgrav=-9.81) ground = Part(ground=True) global_ref = Marker(part=ground) ball = Part(mass=1, ip=[1]*3, cm=Marker(qp=[0,0,10], zv=[0,0,1])) run = model.simulate(type='TRANSIENT', end=2, dtout=0.01, returnResults=True) body_results = run.getObject(ball) #assert type(body_results) == BodyResult time = body_results.times ball_disp = body_results.getComponent('Z') import matplotlib.pyplot as plt plt.plot(time, ball_disp) plt.title('Vertical Displacement') plt.xlabel('time (s)') plt.ylabel('z (m)') plt.grid() plt.show()
- class FlexBodyResult#
Contains results associated with a single FlexBody of the model.
At each output time, the following results are stored:
Components
Label
Index
Center of mass position
X, Y, Z
0 - 2
Euler parameters
E0, E1, E2, E3
3 - 6
Strain Energy
SE
7
Example
For this example, a mtx file is required. The file is located in the mbd_modeling\flexbodies folder in the MotionSolve tutorials Model Files. You may copy the file to your working directory.
from msolve import * model = Model(output='flex_results') ground = Part(ground=True) global_ref = Marker(part=ground) Units(system='MKS') Accgrav(kgrav=-9.81) flex = FlexBody(mtx_file="sla_flex_left.mtx", qg=[0,0,4]) flex_marker = Marker(flex_body=flex, qp=flex.qg, zv=[0,0,1]) vel_request = Request(type="VELOCITY", i=flex_marker, j=global_ref) run = model.simulate (type="DYNAMIC", end=0.5, steps=500, returnResults=True) results_dict = run.asDataFrame() print(results_dict.keys()) flex_df = results_dict[flex] vel_request_df = results_dict[vel_request] print(vel_request_df.columns) import matplotlib.pyplot as plt plt.plot(flex_df['Z'], label="flex cm z-displacement") plt.plot(abs(vel_request_df['VZ']), label="flex lprf z-velocity") plt.xlabel('time (s)') plt.legend() plt.grid() plt.show()
- class PointMassResult#
Contains all the results associated with a single PointMass of the model.
At each output time, the following results are stored:
Components
Label
Index
LPRF position
X, Y, Z
0 - 2
Example
from msolve import * model = Model(output='pmass_results') Units(system='MKS') Accgrav(kgrav=-9.81) ground = Part(ground=True) global_ref = Marker(part=ground) pmass = PointMass(mass=10, cm=Marker(qp=[0,0,10], zv=[0,0,1]), vz=8.0) run = model.simulate(type='DYNAMIC', end=2, dtout=0.01, returnResults=True) pmass_results = run.getObject(pmass) #assert type(pmass_results) == PointMassResult time = pmass_results.times import matplotlib.pyplot as plt # loop over the number of output time steps for i in range(1,200): pmass_disp = pmass_results.getStep(i)[2] plt.scatter(i*0.01, pmass_disp, linewidths=1.0) plt.title('Vertical Displacement') plt.xlabel('time (s)') plt.ylabel('z (m)') plt.grid() plt.show()
- class RequestResult#
Contains all the results associated with a single Request of the model.
At each output time, the following results are stored:
Components
Label
Index
Displacement Request
MAG, X, Y, Z, null, PSI, THETA, PHI
0 - 7
Velocity Request
VM, VX, VY, VZ, WM, WX, WY, WZ
0 - 7
Acceleration Request
ACCM, ACCX, ACCY, ACCZ, WDTM, WDTX, WDTY, WDTZ
0 - 7
Force Request
FM, FX, FY, FZ, TM, TX, TY, TZ
0 - 7
Expression Request
F1, F2, F3, F4, F5, F6, F7, F8
0 - 7
Example
from msolve import * model = Model(output='request_results') Units(system='mmks') Accgrav(kgrav=-9.81) ground = Part(ground=True) global_ref = Marker(part=ground) part = Part(mass=10, ip=[1e3]*3, cm=Marker(qp=[0,0,10], zv=[0,0,1])) spdp = SpringDamper(type = 'TRANSLATION', i = part.cm, j = global_ref, k = 0.05, c = 0.005, force = 50, length = 10, ) vel_request = Request(type='VELOCITY', i=part.cm, j=global_ref) acc_request = Request(f1=f'ACCZ({part.cm.id},{global_ref.id})') run1 = model.simulate(type='DYNAMIC', end=5, dtout=0.01, returnResults=True) spdp.c = 0.05 run2 = model.simulate(type='DYNAMIC', end=8, dtout=0.01, returnResults=True) vel_results = run1.getObject(vel_request) acc_results = run1.getObject(acc_request) df = vel_results.getDataFrame() df.columns time = acc_results.times acceleration = acc_results.getComponent('F1') import matplotlib.pyplot as plt plt.plot(df.VZ) plt.plot(time, acceleration) plt.title('Part Velocity & Acceleration time-histories') plt.legend(['Velocity', 'Acceleration']) plt.xlabel('time (s)') plt.grid() plt.show()
- class RvResult#
Contains all the results associated with a single Rv of the model.
At each output time, the following results are stored:
Components
Label
Index
Value of the integral of the Rv
RVAL
0
Value of the Rv
RVAL1
1
Example
from msolve import * model = Model(output='rv_results') ground = Part(ground=True) global_ref = Marker(part=ground) Units(system='mks') Accgrav(kgrav=-10) part = Part(mass=100, ip=[1,1,1], cm = Marker(qp=[0,0,1])) c = Dv (b=0.1, blimit=[0.01, 1]) spdp = SpringDamper (type="TRANSLATION", i=part.cm, j=global_ref, k=1, c=c) rv = Rv(function=f"DZ({part.cm.id})") run = model.simulate(type="STATIC", end=0.5, steps=20, returnResults=True, dsa='AUTO') rv_output = run.getObject(rv) time = rv_output.times rv_rval = rv_output.getComponent('RVAL') rv_rval1 = rv_output.getComponent('RVAL1') import matplotlib.pyplot as plt plt.plot(time, rv_rval, label="rval") plt.plot(time, rv_rval1, label="rval1") plt.xlabel('time (s)') plt.legend() plt.grid() plt.show()