MotionSolve 2019 Tutorials
MotionSolve 2019 Tutorials
Tutorials
altairhyperworks.com
Intellectual Property Rights Notice
Copyrights, Trademarks, Trade Secrets, Patents & Third Party Software Licenses
Note: Pre-release versions of Altair software are provided ‘as is’, without warranty of any
kind. Usage of pre-release versions is strictly limited to non-production purposes.
Altair Feko™ ©1999-2014 Altair Development S.A. (Pty) Ltd.; ©2014-2019 Altair Engineering Inc.
Note:
Compute Manager™ ©2012-2017 is now part of Altair Access
PBS Desktop™ ©2008-2012 is now part of Altair Access, specifically Altair Access
desktop, which also has Altair Access web and Altair Access mobile
Altair intellectual property rights are protected under U.S. and international laws and treaties.
Additionally, Altair software is protected under patent #6,859,792 and other patents pending. All other
marks are the property of their respective owners.
ALTAIR ENGINEERING INC. Proprietary and Confidential. Contains Trade Secret Information.
Not for use or disclosure outside of Altair and its licensed clients. Information contained in Altair
software shall not be decompiled, disassembled, “unlocked”, reverse translated, reverse engineered,
or publicly displayed or publicly performed in any manner. Usage of the software is only as explicitly
permitted in the end user software license agreement. Copyright notice does not imply publication.
Altair Engineering Inc. and its subsidiaries and affiliates reserve the right to embed software security
mechanisms in the Software for the purpose of detecting the installation and/or use of illegal copies of
the Software. The Software may collect and transmit non-proprietary data about those illegal copies.
Data collected will not include any customer data created by or used in connection with the Software
and will not be provided to any third party, except as may be required by law or legal process or to
enforce our rights with respect to the use of any illegal copies of the Software. By using the Software,
each user consents to such detection and collection of data, as well as its transmission and use if an
illegal copy of the Software is detected. No steps may be taken to avoid or detect the purpose of any
such security mechanisms.
To contact an Altair support representative, reference the following table or the information available on
the HyperWorks website: www.altairhyperworks.com/ClientCenterHWSupportProduct.aspx.
Israel [email protected]
Malaysia [email protected]
For questions or comments about this help system, send an email to [email protected].
In addition, the following countries have resellers for Altair Engineering: Colombia, Czech Republic,
Ecuador, Israel, Russia, Netherlands, Turkey, Poland, Singapore, Vietnam, Indonesia
Official offices with resellers: Canada, China, France, Germany, India, Malaysia, Italy, Japan, Korea,
Spain, Taiwan, United Kingdom, USA
Optimization-DOE-Stochastics..................................................................................... 99
7
MV-7003: Simulating a Single Input Single Output (SISO) Control System Using
MotionView and MotionSolve........................................................................................... 199
MV-7004: Inverted Pendulum Control Using MotionSolve and MATLAB.................................. 203
MV-7005: Linking Matlab/Simulink Generated Code (Simulink Coder) with MotionSolve........... 210
MV-7008: Co-simulation with AcuSolve............................................................................ 220
MV-7009: Remote Co-simulation with Simulink................................................................. 237
Appendix...............................................................................................................250
MV-7010: Co-Simulation with Activate - Quadrotor Control................................................. 252
Index.................................................................................................................................268
8
Rigid Body Dynamics 1
Rigid Body Dynamics
A surface mesh is defined as an interconnected set of triangles that accurately represent the surface of
a 3D rigid body. MotionSolve prescribes certain conditions for such a surface mesh.
• Each component mesh should form a closed volume. This means that the given mesh should not
contain any open edges (edge which is part of only one element) or T- connections (2 elements join
at the common edge in form of a T).
• Mesh should be of uniform size.
• Element surface normal should point in the direction of expected contact.
For these purposes, you will make use of a slotted link model.
For such a meshed representation of 3D rigid bodies, MotionSolve uses a numerical collision engine that
detects penetration between two or more surface meshes and subsequently calculates the penetration
depth(s) and the contact force(s).
There are numerous 3D contact applications (gears, cams, mechanisms with parts in contact etc.) that
may be solved using this approach.
Such mechanisms find common application in valve actuators, air compressors, certain reciprocating
and rotary engines among others. The figure below illustrates a slotted link mechanism that will be
modeled in this tutorial.
This option tells HyperMesh to mesh the CAD geometry such that it can be used for 3D
contact in MotionSolve.
Note: The slider controls the coarseness of the generated mesh, with 1 being
the coarsest and 10 being the most fine. A very coarse mesh will have large
triangles, which may not represent the curvature of the CAD surfaces accurately.
Alternatively, a very fine mesh will have extremely small triangles that may
increase element numbers and thereby the solution time. The best practice is
to strike a balance between mesh fineness and performance that satisfies the
modeling purpose.
At this stage, the Import CAD or FE dialog should look like the figure below:
5. Click OK.
MotionView invokes HyperMesh in the background, to mesh the geometry and calculate its volume
properties. Another dialog appears where the components in the CAD file can be reviewed along
with their mass, density, and volume properties.
Figure 4: Displaying Mesh Lines for all the Components of the Input CAD Geometry
Figure 5: Displaying the Surface Mesh for all the Components of the Input CAD Geometry
Pin Rigid Body The pin body. Together the cam and the pin bodies
engage the slotted link.
Link Rigid Body A connector body between the pin and the cam.
Slotted_Link Graphic The graphic that represents the slotted link body. This
is a tessellated graphic.
Cam Graphic The graphic that represents the cam body. This is a
tessellated graphic.
Pin Graphic The graphic that represents the pin body. This is a
tessellated graphic.
Link Graphic The graphics that represent the link body. This is a
tessellated graphic.
The Pin, Link, and the Cam bodies are fixed to each other and pivoted with to the Ground Body at the
Cam center. The Slotted link can translate with respect to the Ground Body.
S.No
Label Type Body 1 Body 2 Origin Alignment
Axis
3 Cam Pivot Revolute Joint Cam Ground Body Global Origin Global Y
2. Apply a motion on the Cam Pivot joint of the type Displacement and the Expression as
`360d*TIME`.
3. Save your model as slotted_link_mech.mdl.
Figure 6:
3. From the Connectivity tab of the Contact panel, resolve Body I to Cam and Body J to
Slotted_Link. Doing this will automatically select the respective graphics that are attached to
these bodies.
Figure 7:
4. To make sure that the geometries are well defined, ensure that the normals are oriented correctly
and there are no open edges or T-connections in the geometries.
5. Activate the Highlight contact side check box. This will color the geometries specified for
this contact force element according to the direction of the surface normals. Verify that both
geometries are completely red (to visualize clearly, you may have to deactivate the other graphic
and reactivate).
Figure 8:
The color red indicates the direction of surface normal and is the side of the expected contact.
6. Check for open edges or T-connections. If the associated graphics mesh has any open edges or T-
connections, the Highlight mesh errors option is active. If it is active, check the box for Highlight
mesh errors.
Any open edges or T Connections in the geometry are highlighted.
The graphics associated in this contact entity don't have mesh errors. Hence you should see
Highlight mesh errors grayed out.
Figure 10:
The geometry seems to be clean and there are no free edges or T connections in the model.
Note: For every contact entity added to the model, MotionView automatically creates
an output of the type Expression that can be used to plot the contact forces for
that contact element.
7. Specify the contact properties. Click on the Properties tab to display the Normal Force and the
Friction Force property sub-tabs within the Contact panel. In this model you will use an Impact
model with the following properties:
Stiffness 1000.0
Exponent 2.1
Damping 0.1
Figure 11:
8. Repeat Steps 1 - 7 for creating contact between the Pin body (Body I) and the Slotted_Link (Body
J). You may define the label for this contact to be Pin Slotted Link Contact. Define the same
contact properties as listed in Step 7 above.
9. For the contact force element Pin Slotted Link Contact, you will also instruct MotionSolve to find
the precise time at which contact first occurs between the two colliding bodies.
a) Navigate to the Advanced tab.
b) Check the Find precise contact event box.
c) In the text field below, specify a value of 0.01.
Figure 12:
Note: With the Find precise contact event option, MotionView automatically
adds a sensor entity (defined by Sensor_Event in the solver deck), which has a
zero_crossing attribute. During simulation, when the contact force is detected
for the first time (force value crossing zero), MotionSolve will cut down its step
size by the given factor and try to determine the contact event more precisely.
2. Change the Simulation type to Transient and specify an end time of 3.0 seconds.
3. To obtain accurate results, you will specify a smaller step size than the default.
a) Click on Simulation Settings to display the Simulation Settings dialog.
b) Go to the Transient tab and set the Maximum Step Size to 1e-3.
c) Click Close.
4. From the Run panel, specify a name for your XML model and click Run.
The transient simulation is started.
Figure 14: Specify the Output File Name and Run the Model
In the HyperWorksHyperWorks Solver View dialog that appears, you should be able to see a
message from the solver that confirms that the mesh based contact method is being used for the
contact calculations.
Figure 15: Verifying That the Mesh Based Contact is Used for the Simulation
In the log file you will also see messages related to the sensor. This is related to finding the
precise contact event for the second contact element in the model.
1. To view a consolidated report of the results, click Analysis > View Reports.
Figure 18:
A list of the history of simulations you have completed in the past using MotionView is displayed.
2. Select the Contact Report that corresponds to this simulation.
3. Click OK.
The first HyperView page (second in the session) displays a contour plot colored by maximum
penetration depth over the entire length of the simulation. You may hide one or more parts to view this
clearly in the modeling window. This is illustrated in the figure below. The cam graphic has been made
transparent to see the penetration depths better.
Note: The contact overview colored by penetration depth is only available for meshed
geometries.
Figure 21:
2. Click Animation Controls on the Animation toolbar and move the Animate End slider to the
end .
3. Click Contour on the toolbar and select the Cam body as the Components collector.
4. Click Apply.
5. Click on the Start/Pause Animation button to animate the result.
The penetration depth contour animation on the cam body can be visualized.
1. Click Animation Controls on the Animation toolbar and move the Animate End slider to the
end .
Figure 23: The Total Contact Force Between the Cam Body and the Slotted Link
The current force vectors are displayed on each node of the mesh that is in contact at each time
step.
1. From the Results Browser deactivate the following components: Contact Graphic(Cam Slotted
Link Contact) and Contact Graphic (Pin Slotted Link Contact).
2. Activate the Contact Region Output (by either clicking on the icon in the browser or using the
right-click context menu).
2. For the Result type, select the type of result from the drop-down menu and click Apply.
This will plot the result type you selected for all the relevant graphics in the model. You may have
to scale the force vectors accordingly to make sure they are visible.
As an example, the point slip velocity vectors are plotted in the figure below:
Navigate to the next page . This is the last page in the session.
Each time a new contact entity is created in MotionView, a corresponding output force request is
created that can be used to plot the contact forces between the graphics specified in the contact entity.
These can then be visualized in HyperGraph. The last page of the contact report plots the contact force
magnitude for all the contact elements in the model.
1. Click Add Page and change the client to HyperGraph 2D (if it is not already selected).
3. Under Y Type, select Expressions and select a request in the Y Request window.
Select REQ/70000003 Force - Pin Slotted Link Contact as the Y Request and F4 as Y
Component to plot.
4. Click Apply.
Summary
In this tutorial, you learned how to create a good meshed representation from CAD geometry. Further,
you learned how to setup contact between meshed geometries. Also, you were able to inspect
the geometry to make sure the surface normals were correct and there were no open edges or T
connections.
You were also able to setup a transient analysis to calculate the contact forces between these
geometries and post-process the results via vector and contour plots in addition to plotting the contact
force requests.
Sequential Simulation
Often, the total dynamic behavior of a multibody model needs to be captured through more than one
solution sequence. Typical examples include:
Such conditions may be simulated by providing a set of commands to the solver that achieves the
above type of sequences. Such simulations are referred to as sequential simulations. Generally, the
solver receives more than one solution (simulate) command. You'll learn to script such a simulation
sequence through this exercise.
Exercise
In this exercise, a landing gear mechanism is simulated for its extension and retraction. A sequence
of simulations need to be scripted such that the mechanism is retracted within a certain period of time
at which the simulation is halted, the model configuration is changed for retraction and the solution is
executed again for extension.
Phase 1
In this phase, you will prepare the landing gear model to simulate the retraction of the landing gear.
Or
2. From the Open model dialog, select the file MainLandingGear.mdl and click Open.
Once the model is loaded it will look as it does below. Review the model for its bodies and joints.
The model consists of linkages of the cylinder and piston that hold the wheel as well as linkages
for the extension and retraction of the whole landing gear unit within the aircraft body. The model
also contains a body defined for aircraft but without graphics. As a first step, you’ll add a graphic
for the aircraft body part for visual representation.
Figure 31: The Model After Importing a Graphic for the Aircraft Body
Note: Since the H3D file has only one component, aircraft_body, the Component
list can be set to either All or select the only component from the drop-down
menu.
Figure 32:
1. From the Project Browser, right-click on Model and select Add Constraint > Motions (or right-
click Motions from the toolbar).
4. From the Motion panel > Properties tab, under Define by, select Expression. In the Expression
field, enter the expression STEP(TIME,0,0,5,-750).
Note: The above STEP expression ramps the value of motion from 0 at 0 second to
-750 at 5 seconds. .
5. Add another motion and name it Aligning_Motion. Resolve the Joint to the Cylindrical Joint
LnkCyl_LnkPis_Cyl defined between the MLG Cyl and MLG Pis bodies (see the image below).
6. From the Properties tab of the panel, under Define by, select Expression. In the Expression field,
enter the expression STEP(TIME,0,0,2,-100).
7. Save your model as landinggear_motion.mdl.
Phase 2
In Phase 2, write a Templex template to script and run a sequential simulation to simulate the retraction
and extension of the landing gear mechanism.
1. From the Project Browser, right-click Model and select Add Constraint > Motions (or right-click
Motions from the toolbar).
2. Add another motion with Label as Extension Motion and Variable Name as mot_ext. Resolve the
motion to the same joint for which the Retraction Motion has been defined.
3. From the Properties tab, set the type of motion as Expression and enter the following in the
Expression field: STEP(TIME,5,-750,10,0).
1. From the Project Browser, right-click on Model and select Add > General MDL Entity >
Template (or right-click Template from the toolbar).
Note: The following commands are MotionSolve command statements in the XML
format. Since the solver refers to entities through their ID numbers, the element_id
value is resolved to the motion IDs. If you have used different varnames for the
motions than mentioned below, the text could differ.
/>
<STOP/>
<!-- Stop the simulation. Any further commands below this command will not be
executed -->
Block 2 Simulates the model for the retraction of the landing gear.
Block 5 Simulates the model for the extension of the landing gear.
The Stop command is used to stop the simulation at the time set in the last Simulate block.
Note: A template can be used either to add modeling entities to the solver deck, such
as joints, markers, and so on, that may not be supported by MotionView, or command
entities such as simulation parameters, activation and deactivation, and so on. The
MotionSolve XML is divided into two sections.
Model Section All model elements are defined. To write to this section
from the template, for Type select Write text to
Solver input deck.
1. From the Run panel, specify the file name as MLG_Simulation.xml and click Run.
2. Once the solution is complete, close the HyperWorks Solver View window.
3. Click Animate and review the animation.
Phase 3
In this phase, you will create output requests and re-run the model to measure the Angular
Displacement and Angular Velocity of the landing gear.
1. From the Project Browser, right-click on Model and select Add > General MDL Entity >
Outputs (or right-click Outputs , from the toolbar).
Figure 35:
Figure 36:
The Import CAD or FE utility in MotionView allows you to import CAD or FE assemblies. CAD formats
include CATIA, Parasolid, Pro E, STEP, JT, SolidWorks and Unigraphics. FE formats include HyperMesh,
OptiStruct, and Nastran.
CAD or FE assemblies can be imported into MotionView as graphics only to be associated with existing
bodies, or as new bodies with calculated mass and inertia properties along with graphics.
The multibody aspects of any CAD assembly that can be imported in MotionView are:
• Component Mass
• Component Moments of Inertia
• Component Center of Gravity Location
• Component Graphics
The CAD import utility calls HyperMesh in the background to write out a graphic file (*.h3d) which holds
the geometry information in a tessellated form. While importing CAD or FE to create new bodies with
mass and inertia, the utility uses HyperMesh to calculate mass, inertia and CG location.
In the following exercise, you will import a CAD assembly into MotionView, simplify the model from a
multibody analysis point of view, and define constraints, model inputs and model outputs.
Please copy all of the files from the mbd_modeling\automation\CAD folder into your <working
directory>.
2. From the menu bar, select File > Import > Geometry
Or
Figure 37:
Note: The MDL Options allow for flexibility while importing. The CAD file can be
imported either in an existing system/assembly or a new system can be created
Figure 38:
Note: This section helps control the size of mesh (or tessellation). When the MBD
model being created is used to solve non-contact problems, use the default option
under Allow HyperMesh to specify mesh options. The Launch HyperMesh to create
MDL points option allows you to select nodes in HyperMesh which can be imported
into MotionView as MDL points. This is not needed for this tutorial since you will be
creating these additional points using a macro. For models that involves contacts,
it is recommended to use Control mesh coarseness for contacts. The Interactive
mesh (launches HyperMesh) option can be used to mesh the surfaces manually. This
is particularly useful when a finer mesh may be needed, such as in case of contact
problems, to obtain better results.
11. Click the plus button next to Locator Points (must be in source reference frame) and review the
options.
Figure 39:
Note: The Locator Points options can be used in cases where the CAD model being
imported is not in the same coordinate system as the MBD model in MotionView.
This option gives you control to specify three nodes or coordinates on the source
graphic which can then be used to orient using three points in MotionView after it's
imported. This option is not needed for tutorial as the imported graphic is in the
required position.
Note: This dialog helps to generate mass and inertia information. The table displays
different bodies or components being imported along with the volume and mass
information based on a default density of 7.83e-6. The density value can be modified
for each of the components. Alternatively, a CAD summary file can be used to extract
mass/inertia
16. Leave the default value of the density for the other components. Click OK.
If the import into MotionView is successful, the message "Translating/Importing the file
succeeded!" is displayed in the message log.
17. Clear the message log.
The body, along with the associated graphics, is displayed in the modeling window.
Note: The Extract mass/inertia data from CAD summary file option can be used only
for CATIA summary file. Currently, summary files from other CAD packages are not
supported under this option.
Figure 41:
2. Select Merge Bodies. This option is used to merge two or more bodies into a single body.
3. From the Merge Bodies dialog, enter Strut_rod as the label and b_Strut_rod as variable name.
Click OK.
The three selected bodies are deleted and replaced by a new body with the label and variable
names as entered previously. The mass and inertia values of this body are equivalent to the
effective mass and inertia of the bodies being replaced.
Figure 42:
1 Wheel_Hub_body1 Wheel_Hub
2 Lower_Control_Arm_body1 Lower_Control_Arm
3 Axle_Shaft_body1 Axle_Shaft
Figure 43:
Creating Points
After creating the bodies, additional points are needed that will be used to specify joint locations and
joint orientations. These points can be created using the macros available in the Macros menu.
1. From the Macros menu, select Create Points > Using Coordinates or click Create points
using Coordinates .
Figure 44:
Figure 45:
Figure 46:
Note: To use this macro import option, you have to create the *.csv file in the format
shown below:
Figure 47:
1. From the Project Browser, right-click Model and select Add > Constraint > Joint (or right-click
Joints from the toolbar).
The Add Joint or JointPair dialog is displayed.
2. Specify the Label and Variable as Wheel Spindle RJ and j_whl_spindle_revj, respectively.
3. For Type, select Revolute Joint.
4. Click OK.
5. Make the following selections:
a) For Body1 of the joint, specify Wheel.
b) For Body2, specify Wheel_Hub.
c) For Origin, specify Point7. (Point around the Wheel center).
d) For Axis, specify Point19. (Point around Axle Shaft center).
Figure 48:
6. Add the rest of the joints of the model using the table below:
7. From the Project Browser, right-click Model and select Add > Force Entity > Spring Dampers
(or right-click Spring damper icon from the toolbar).
2. Add a body with Label and Variable as Jack and b_jack, respectively.
3. Click the body Properties tab and specify the Mass and the three principle inertia values of the
body as 0.01, 100, 100, and 100, respectively.
4. Click the CM Coordinates tab and select the Use CM Coordsys check box.
5. Pick Point10 (bottom of wheel body) as the CM Origin point for the jack body.
6. From the Project Browser, right-click Model and select Add > Reference Entity > Graphic (or
right-click Graphics from the toolbar) to add a graphic.
7. Specify the Label of the graphic as Jack Plate and select the Type as Cylinder from the drop-
down menu.
8. Accept the default variable.
9. From the Connectivity tab, select the Parent Body as Jack.
10. Pick Point10 as the Origin. For Direction, toggle to Vector and select Global Z.
11. Click the Properties tab. Specify a value of -30 in the field next to it.
12. Specify a value of 250 for Radius 1.
Notice that the Radius 2 field is updated with the same value as Radius 1.
13. From the Project Browser, right-click Model and select Add > Constraint > Joint (or right-click
Joints from the toolbar).
14. Specify the Label and Variable as Jack Wheel Inplane and j_jack_wheel, respectively.
15. For Type, select Inplane Joint from the drop-down menu.
16. Click OK.
17. From the Connectivity tab, select Wheel as Body1, select Jack as Body2.
18. Select Point10 as Origin and Vector Global Z as Normal.
19. Add another joint and specify the Label and Variable as Jack Ground Trans and j_jack_grnd,
respectively.
20. For Type, select Translational Joint.
21. Click OK.
22. From the Connectivity tab, select Jack as Body1, Ground Body as Body2.
23. Pick Point10 as Origin and Vector Global Z as the Alignment Axis.
All the joints required to complete the model are now in place.
24. Save the model.
1. From the Project Browser, right-click Model and select Add > Constraint > Motion (or right-
click Motion from the toolbar) to add a motion.
9. Click Check Model . In the Message Log that is displayed, verify that there are no warnings or
errors. Clear the message log.
10. Go to the Run panel .
11. Specify a name for the MotionSolve input XML file by clicking Save and run current model .
Sequential Simulation allows you to write simulation instructions to change the model, modify the solver
settings and submit analyses.
OR
From the File menu, select Open > Model to open the model Sequential_simulation.mdl.
The model contains two bodies, namely a slider and a picker. You need to create markers, joints,
and a sensor as well as use Templex statements to perform a sequential simulation.
Figure 50:
3. From the Project Browser, right-click on Model and select Add > Constraint > Joint (or right-
click Joints from the toolbar).
4. Under Type, select Translational Joint. Label the joint slider trans.
5. Make the following selections:
a) For Body 1, select slider.
b) For Body 2, select Ground Body.
c) For Origin, select slider cg.
d) Define the Alignment axis using the point slider end.
Figure 51:
6. Add another joint. For Type, select Fixed Joint and label the joint picker rest fix.
7. Make the following selections: s
a) For Body 1, select picker.
b) For Body 2, select Ground Body.
c) For Origin, select part fix.
This joint will be deactivated when the slider body coincides with the picker body during
simulation.
Figure 52:
When you create a fixed joint between the slider and the picker and they come in contact, you
need to define two markers which are initially not coincident, but coincide during the course of
simulation. Creating a joint based on markers must be done using Templex, as it is not possible to
create it from the user interface.
8. From the Project Browser, right-click Model and select Add Reference Entity > Marker (or
right-click Marker from the toolbar). Label it Marker Slider Track and set the properties as
shown in the image below:
Figure 53:
9. Similarly, create another marker with the label Marker Picker Track and set the properties of
the markers as shown in the image below:
Figure 54:
10. From the Project Browser, right-click Model and select Add Control Entity > Sensor (or right-
click Sensor from the toolbar) to add a new sensor.
11. From the Signal field, select the type as Expression and enter the following expression:
`DX({the_model.m_0.idstring},{the_model.m_1.idstring})`
12. In the Compare to field, enter 0.0010 for the Value and 0.0010 for Error. Set Respond if to Signal
is greater than VALUE - ERROR.
13. In the Response field, select Return to Command File.
This directs the solver to look into the template for further instruction on how to proceed once the
signal is attained.
14. From the Project Browser, right-click on Model and select Add Constraint > Motion (or right-
click Motion from the toolbar. Set the properties as shown in the figure below.
Figure 55:
Figure 56:
2. Label it Fixed Joint Defn. For Type, select Write text to solver input deck. Enter the
following commands as they are listed below in the same order.
<Constraint_Joint
id = "5000"
type = "FIXED"
i_marker_id = "{the_model.m_0.idstring}"
j_marker_id = "{the_model.m_1.idstring}"
/>
Figure 57:
1. From the Project Browser, right-click on Model and select Add General MDL Entity > Template
(or right-click Template from the toolbar).
<ResOutput
plt_angle = "YAW_PITCH_ROLL"
/>
<ResOutput
mrf_file = "TRUE"
/>
<ResOutput
plt_file = "TRUE"
/>
<H3DOutput
switch_on = "TRUE"
increment = "1"
/>
<ResOutput
abf_file = "TRUE"
/>
<Deactivate
element_type = "JOINT"
element_id = "5000"
/>
<Simulate
analysis_type = "Transient"
end_time = "3.5"
print_interval = "0.01"
/>
<Deactivate
element_type = "JOINT"
element_id = "{the_model.j_1.idstring}"
/>
<Deactivate
element_type = "SENSOR"
element_id = "{the_model.sen_0.idstring}"
/>
<Activate
element_type = "JOINT"
element_id = "5000"
/>
<Simulate
analysis_type = "Transient"
end_time = "5."
print_interval = "0.01"
/>
<Stop/>
Figure 58:
MotionView provides the modeling tools required to incorporate flexible bodies in your MBD model.
Flexible MBD simulations allow you to:
• Capture body deformation effects in simulations.
• Acquire greater accuracy in load predictions.
• Study stress distribution in the flexible body.
• Perform fatigue analysis.
However, flexible bodies introduce an additional set of equations in the system and consequently, have
a higher computational cost as compared to rigid body systems.
where:
is modal matrix
Note: At the end of this tutorial, links to online help direct you to where you can learn more
about the theory behind flexible bodies and CMS method.
Figure 59:
Note: You can manually edit the preparation file generated by FlexPrep to reduce the
size of the flexible body H3D.
Once the flexbody H3D is created, it can be used in the MBD model and the model can be submitted to
either MotionSolve or ADAMS. This is covered in the following tutorials.
Tutorial Objectives
• Get familiar with the flexible body generation techniques available in MotionView and OptiStruct.
• Be introduced to all available features in FlexBodyPrep for flexbody generation.
• Be introduced to the various options available in OptiStruct to reduce the size of the H3D file.
There are two ways you can generate the flexible bodies for MBD simulation in HyperWorks:
1. Using FlexPrep utility in the MotionView interface.
2. Manually editing the input deck (*.fem) for OptiStruct solver.
In this exercise, you will generate a flexible body for a left Lower Control Arm of a front SLA suspension.
The input file is a pre-prepared .fem file (sla_flex_left.fem) which has finite element modeling
information for the LCA (elements and nodes). Interface nodes for the flexible body are:
• The center nodes at the front and rear bushing mounts
• Location where the spring is attached
• The center of the lower ball joint attaching to the knuckle.
In the given input file, interface nodes are already created at the center of the bushing mounts and the
spring attachment location. You will create the interface node at the lower ball joint and its connection
to the LCA in the exercise.
Using FlexBodyPrep
Once you provide the required input, Flex Prep generates an input deck (_prp.fem) for the OptiStruct
solver with all the required cards, and then it calls OptiStruct to run the job. Please refer to MV-2000:
Introduction to Flexible Bodies to understand all the inputs and process.
Note: You can use any OptiStruct (FEM) or Nastran (.nas, .dat, .bdf) bulk data files.
6. For Save the *.h3d file as, enter the name of the output H3D file as sla_flex_left.h3d in your
<working directory>.
7. For the Component mode synthesis type, select Craig-Bampton to perform Craig-Bampton
component mode synthesis.
8. In the Specify Interface Node List field, enter 10001+10002+10003.
Note: If the interface node IDs are within a range, you can specify as 10001:10003.
The interface nodes are the nodes where constraints or forces are applied in the MBD analysis.
9. For the Cutoff type and value, select Highest Mode # and enter a value of 10.
Limiting Modal Information
MotionView allows you to specify a limit on the modal information contained in your H3D file. Two
methods are available to set these limits.
• Specify a maximum number of Eigen modes for which modal data is included in your H3D
• Specify an upper cut-off frequency for the Eigen modes. When a cut-off frequency is specified,
normal modes analysis can be performed using one of two algorithms: Lanczos or the automated
multi-level sub-structuring eigenvalue solution, AMSES.
With this option set, Flex Prep puts relevant cards in the OptiStruct input deck to calculate
the modal strains while processing your bulk data file.
Note: The Create Recovery H3D option is useful in fatigue analysis. A smaller
flex H3D file is generated that contains the minimum amount of information
required for MBD simulation in MotionSolve. A larger file, *_recov.h3d, is
also generated that contains additional information for displacement, velocity,
acceleration, stress, and strain. Refer to Recovering MBD Analysis Results in
OptiStruct to learn more about using this method for fatigue analysis.
11. Under Specify units in bulk data file, select the following:
Length Millimeter
Force Newton
Time Second
Note: HyperMesh is unit-less and you need to make sure to use consistent units, or
the flexbody generated will have incorrect modal frequencies. In the given input file,
the density used is in unit kg/mm^3. Hence, you will use kilogram as the mass unit in
this exercise.
Generally, FE analysts using mm-N-sec as Length, Force and Time units need to specify mass as
a derived unit as N-sec^2/mm (equivalent to tonne/mm^3/MEGAGRAMS). If the model that you
use in the future may have such units, use MEGAGRAMS for the mass units in FlexBodyPrep.
There are three RBE2 spiders already in sla_flex_left.fem. The fourth RBE2 spider should be
created using the Create RBE2 Spiders option explained in the next step.
Note: If the finite element model definition is complete (all interface nodes and connections
already exist), this step is not required.
An RBE2 is a rigid element whose independent degrees of freedom are specified at a single grid point
and whose dependent degrees of freedom are specified at an arbitrary number of grid points. This is
usually used to model relatively stiff connections.
HyperMesh is invoked. The input file, sla_flex_left.fem, is imported into HyperMesh and the FE
model is displayed in the modeling window of the screen.
2. If HyperMesh asks for a user profile, click Cancel and go to the Utility menu in the browser area.
Figure 60:
The tab area displays a Utility tab with a user-defined page with three buttons (steps 1 to 3).
3. If the user defined page with the three buttons is not displayed, follow these steps to view it:
a) From the View menu, select Utility menu.
b) From the Utility menu, click User , located at the bottom of the page.
4. Click Info to view the details regarding the procedure to create RBE2 spiders.
Figure 61:
5. Zoom into the area of the lower ball joint location as shown in the image below:
Figure 62:
Figure 63:
8. Click Step 3: Save and Close, which will save the modified file and automatically grab the ID of
the center (interface) node. Give a new name to the file sla_flex_left_complete.fem and check
to see if the interface node ID is added to the flex prep.
The new interface node IDs are automatically added to the interface node list in FlexBodyPrep as
displayed in the image below:
Figure 64:
1. From the Select window mode drop-down menu on the toolbar, select HyperView.
The Load model and results panel is displayed.
2. Click the Load model file browser and select the H3D flex file, <working directory>/
sla_flex_left.h3d.
HyperView automatically updates the Load results file field with the same filename. The flexible
arm model and its modal results are contained in the H3D flex file you created using the Flexprep
wizard.
4. Click Select animation mode and select Set Transient Animation Mode .
7. Click Select animation mode arrow and from the drop-down list, select Set Modal Animation
Mode.
8. To animate a particular mode shape, go to the Results Browser and change the mode from
Undeformed Model Frame to Mode 7.
Figure 67: Selecting Specific Mode using the Simulation Selector Panel
Note: Although there is not a direct correlation possible, you can recognize the first
six modes as rigid body modes due to near zero frequency values. If there are more
than six modes that are near zero, it generally indicates a model integrity problem
(one or more elements are free and not connected to other elements).
Figure 68:
12. From the Result type drop-down menu, select Stress and vonMises. For Entity with layers, select
Z1 as shown in image below:
Figure 69:
13. Click Apply to display the contours and the legend in the modeling window.
The above exercise demonstrated generating a flexible body using MotionView. Flexible bodies can also
be generated by using HyperMesh and OptiStruct. To learn more, you can refer to tutorial OS-1930 -
Generating a Flexible Body for use in MotionSolve.
<install_path>/altair/scripts/flexprep
<install_path>\io\translators\bin\<os>\flexprep.exe
The usage options and corresponding syntax is listed if the above command is given without any
arguments.
The sla_flex_left.h3d flexbody created in the earlier exercise is the lower control arm of a left front
SLA suspension. Now, we will create a symmetric flexible body for the right front SLA suspension by
invoking flex prep in batch mode.
Note: In this exercise, you will run the FlexPrep translator from the MS DOS prompt for the
Windows operating system. You may follow analogous steps for the Unix terminal.
Line 3: CMSMETH 1
Line 4: STRESS=ALL
Line 5: STRAIN=ALL
Line 6: BEGIN BULK
A generalized input deck (FEM file) need the cards specified above to generate a flexbody from
OptiStruct. The definition of each line is as follows:
Line 2: OUTFILE - used to specify a base name for the H3D file.
Line 3: CMSMETH - is the card defining the component mode synthesis solution method used to
generate flexbodies in OptiStruct.
Line 4: STRESS=ALL - use to specify that modal stresses are to be computed by OptiStruct for all the
elements in the model.
Line 5: STRAIN=ALL - use to specify that modal strain values are to be computed by OptiStruct for all
the elements in the model.
Line 8: PARAM COUPMASS -1 - defines values for parameters used by OptiStruct for the generation of a
flexbody. In this case, lumped mass matrix approach is used by OptiStruct for eigenvalue analysis.
Line 9: PARAM CHECKEL YES - parameter to perform element quality check before running the job.
Specifying NO makes the solver skip the element check. Elements with poor quality may lead to
inaccurate results.
Line 10: CMSMETH CB 10 - component mode synthesis method selected is Craig Brampton and 10
modes are requested.
Lines 11 to 14: ASET1 - defines the boundary degrees of freedom for the interface nodes.
With these cards specified, OptiStruct generates a flexbody H3D file. The flexbody size can be large
based on the bulk data file, number of interface nodes, and modes and stress/strain details. It is
possible to reduce the size by using any of following methods:
• MODEL Set - Reduces the model information that is used for graphical display.
• STRESS/STRAIN Set - Reduces the number of elements on which stress or strain calculation is
requested.
• OUTLINE - Reduces the model information to display only boundary edges.
• Reduced DOF - Reduces the number of DOF that contribute to the flexible body information.
Modifying the Input Deck to Incorporate Stress/Strain Set, Model Set, Outline and Released DOF into
the Flexbody
In finite element modeling, nodes or elements can be grouped together to form a SET. These groups
can then be used in other modeling cards that can take the nodes and elements as inputs collectively.
In flexible body generation, the need to incorporate these sets in the OptiStruct input deck is:
• To reduce the size of the flexbody.
• To help increase the speed of the multibody pre-processing, simulation and animation.
If NONE is specified, the stress is not calculated on any elements. (Not having the STRESS card has the
same effect).
In the FEM file that is opened, you can observe SET cards defined for nodes (keyword GRID) and
elements (keyword ELEM).
1. Modify the cards STRESS=ALL and STRAIN=ALL as STRESS=5 and STRAIN=5, respectively.
2. Modify the OUTFILE to read as OUTFILE, sla_flex_left_stress_set.
3. Save the file as sla_flex_left_stress_set.fem and close the file.
4. Generate the flexbody using FlexBodyPrep.
a) From the OptiStruct Flexbody Generation drop-down menu, select the option Create h3d
flexbody using pre-existing prp file.
Note: You can use OptiStruct to generate the flexbody. To run OptiStruct from
the command prompt, type the following the working directory: <install>
\hwsolvers\bin\win32\Optistruct.bat sla_left_stress_strain_set.fem.
5. Start a new MotionView session and change the window type to HyperView.
6. Load in the H3D file sla_flex_left_stress_set.h3d generated by OptiStruct.
7. Go to the Contour panel to apply Stress and Strain contours.
You will see that only a few elements display the contours. These are the elements that were pre-
selected for stress and strain computations using the element set.
Where MODEL is the OptiStruct card that determines the elements to be written to the result file (H3D).
setid is the ID of set that defines the element displayed.
PLOTEL EID G1 G2
Where PLOTEL is the element type, EID is the element ID, G1 and G2 are the nodes used to define the
element. For example:
The FEM file that you are working with already contain PLOTEL elements.
Figure 71:
1. Open the FEM deck sla_flex_left_model_set.fem, saved earlier in your working directory.
2. Replace the MODEL=4 by MODEL=PLOTEL.
Within the BULK DATA, you will be able to see the many PLOTEL elements.
3. Change the OUTFILE line to read as OUTFILE, sla_flex_left_plotel_set.
4. Save the file as sla_flex_left_plotel_set.fem.
5. Run the FEM deck in OptiStruct or you can generate the flexbody from FlexPrep.
a) From the OptiStruct Flexbody Generation drop-down menu, select the option Create h3d
flexbody using pre-existing prp file.
6. In HyperView, load the H3D file generated by OptiStruct.
You will see that the flexbody is shown only as lines or edges defined by the PLOTEL elements.
The ASET1 card is used define the boundary degrees of freedom of an interface node of a flexbody.
ASET1 C G1 or ASET1, C, G1
Where ASET1 is the card name, C is the DOF to be constrained, and G1 is the node ID. For example:
This means that the interface node of ID 4927 will be constrained for all DOF, where 123456 represents
the three translational and three rotational nodes in that order. Thus, to release a DOF from the
interface node (for example, rotation about X), the C value will be 12356.
1. Modify the ASET1 card corresponding to interface node 10004 in the deck as follows:
1. From the MotionView menu bar, select Model > Assembly Wizard to bring up the wizard.
2. Use the criteria from the table below to assemble a front end half vehicle model.
Panel Selection
1. Ensure that you have selected Frnt. SLA susp (1 pc LCA) since the flexible bodies you have
created are for this suspension geometry.
2. From the MotionView menu bar, select Analysis > Task Wizard to display the wizard.
3. Load a Static Ride Analysis task from the Task Wizard - Front end tasks. Click Next and click
Finish.
The Vehicle Parameters form is displayed.
4. Click Finish.
5. From the Project Browser, select Lwr control arm from the Bodies folder (located underneath the
FrntSLA Susp (1 pc.LCA) system).
The Bodies panel is displayed.
6. Under the Properties tab for the Lwr control arm-left, deselect the symmetry check-box,
Symmetric properties.
The Remove Symmetry confirmation dialog is displayed.
7. Click Retain to retain the current values of properties of Lwr control arm-right.
8. Select the Flex Body (CMS) check box and click Yes to confirm both sides as deformable.
Figure 72:
Notice that the graphics of the rigid body lower control arm vanishes.
9. Using the file browser select the file sla_flex_left.h3d (created in earlier tutorial MV-2010)
from your working directory.
The H3D file field is populated automatically with the same path and the file name as the graphic
file you specified earlier.
Note: You need to specify the flexbody H3D file as the H3D file. Specify the same or
any other file as the graphic file.
Use of large flexbodies is becoming very common. For faster pre-processing, you can
use any graphic file for the display and use the flexbody H3D file to provide the data
to the solver. You can use the input FEM deck or the CAD file used for the flexbody
generation to generate a graphic H3D file using the CAD to H3D Conversion and
specify that file as the graphic file. This will make pre-processing a much more efficient
process.
1. Click Nodes.
The Nodes panel is displayed.
Figure 74:
The Nodes panel is used to resolve the flexbody's attachments with the vehicle model, since the
vehicle model is attached to the flexible body at these interface nodes.
This panel lists all markers of the connections (joints/forces) on the body which is now flexible.
These markers can interact with the flexible body only through a node. This panel is used to map
each of the markers to a node. The panel also displays the point coordinates of the marker origin
which are nothing but coordinates of a point entity that the connections are referring to.
2. Click Find All on the Nodes dialog to find nodes on the flexible body that are located closest to
the interface points on the vehicle model.
The Node ID column is populated with the interface node numbers for each row of connections.
Also, the node coordinate table is also populated along with the Offset with respect to the point
coordinates.
3. Observe a small offset for the Lwr ball jt-Marker J-left. It suggests a difference in the coordinate
values between the point at which the joint Lwr ball jt is defined and its corresponding location of
the interface node 10004. Click Align to move the point to the nodal coordinate position.
Note: Many times there is a little offset between the flexible body interface node and
its corresponding point in the model. When you click Align, MotionView moves the
connection point in the model to the node location on the flexible body. This could
affect other entities that reference this point. Hence, this option should be used with
caution. Generally, it is common to have minor offsets (values between 0.001mm to
0.1mm). If the offset is more than the tolerance value, MotionView inserts a dummy
body between the flexible body and the nearest connection point. If the offset value is
too high, it could indicate an mismatch of the FE model information with respect to the
MBD model. In such an event, it is recommended to review the models and reconcile
the differences.
Figure 75:
Please note that when selecting the modes, the simulation results may vary as you change the
modes to be included in the simulation.
Note: By default, for frequencies under 100Hz, 1% damping is used. For frequencies
greater than 100Hz and less than 1000Hz, 10% damping is used. Modes greater than
1000 Hz use critical damping. You can also give any initial conditions to the modes.
6. Click Close.
7. Repeat steps 1 through 5 to integrate the right side flexible body sla_flex_right.h3d (created in
MV-2010: Flexbody Generation using Flex Prep and OptiStruct) in your model.
Your model should look like the image below:
Figure 76:
2. From the Tools menu, select Check Model to check your complete MBD model for errors.
3. From the Standard toolbar, click Save Model to save your model as an MDL file named
sla_flex.mdl.
4. Click Run on the toolbar and run the model with simulation type Quasi-Static, specifying the
filename as sla_flex_ride.xml.
5. Once the run is complete, load the MotionSolve result file sla_flex_ride.h3d (located in your
working directory) in a HyperView window and view the animation of the run.
Figure 78:
Figure 79:
2. In the FlexBodyPrep dialog, enter the following information to generate the flexbody for building
the door closure model.
3. Using the image above as a guide, for #2, Select Bulk Data file (fem/nas/bdf/dat):, specify the
input file metro_door_flex.fem generated in Step 1.
4. For #3, Save the h3d file as:, specify the output H3D file as metro_door_flex.h3d.
5. For #4, Specify Interface Node List, specify the interface node numbers as: 9751+9750+10090.
6. For #5, Cutoff type and value: select Highest Mode # and enter 20.
7. For #6, activate both Perform stress recovery and Perform strain recovery, and select No
for Perform element check in OptiStruct model.
For this model, use the following units for length, mass, force, and time, respectively: millimeter,
megagram, Newton, second.
Model Units
From the Forms panel, , change the Mass units from the default Kilogram to Megagram.
Points
For building this model, a total of six points need to be created.
From the Project Browser right-click Model and select Add Reference Entity > Point, or right click
Points from the toolbar. Add the points as shown in the table below.
Bodies
In this model, there are two bodies: one body to represent the car and another to represent the flexible
door.
1. From the Project Browser right-click Model and select Add Reference Entity > Body, or right
click Bodies from the toolbar. Add a body and label it Car Body.
2. From the CM Coordinates tab, specify the center of mass of the body as the point Car Body CG.
3. Click the Properties tab of the Car Body and enter the mass and inertia properties values as
shown below.
Graphics
After Point 6 above, you can see that the Door Body has a graphical representation, but Car Body
does not. You can add a file graphic to the Car Body so that visualization of the model becomes more
meaningful.
Figure 83:
3. Click OK.
The HyperMesh file is converted to H3D and imported into the MotionView window.
5. From the Connectivity tab, double-click Body and pick Car Body as the body.
This will associate the selected graphic with the Car Body.
Joints
For this body, you will need to add a total of four constraints/joints. One of these joints will need to be
added using the XML template.
1. From the Project Browser right-click Model and select Add Constraint > Joint, or right click
Joint from the toolbar.
Once the joints are specified and since there is a flexible body in the model, the interface nodes of
the flexible body have to be associated with corresponding joint markers.
3. From the Bodies panel, select Car Door.
4. From the Properties tab, click Nodes.
5. From the Nodes dialog, click Find All to find the interface node numbers and to resolve them with
the respective connection markers.
Initial Conditions
In this simulation, body initial velocity will act as the primary motion input to the model.
1. From the Project Browser select the Door Body from the filter on the left.
2. Click the Initial Conditions tab.
3. Activate WZ and specify a value of 5.0.
This will be the magnitude of the initial angular velocity about the global Z axis that will be applied
to the Door Body.
4. Do a test simulation to check how the model behaves with just the initial velocity and the
constraints.
Markers
To represent the locking mechanism of the car door, you will use a sensor activated fixed joint between
the Car Body and the Door Body that initially is deactivated. The fixed joint will need to be created
using XML templates since the MotionView interface allows joints to be created using bodies and points.
In this case, you need to create the joint between two initially non-coincident markers.
1. From the Project Browser right-click Model and select Add Reference Entity > Marker, or right
click Bodies from the toolbar.
3. Once the markers are created, repeat steps 2-4 under Joints above to resolve the node
connections of Car Door Body with the maker Door Lock Mark.
Sensors
In this model, you will use an Event Sensor to detect the closing of the door. At the instance of the
event detection, the fixed joint between the door and the car body is activated to simulate the actual
locking mechanism.
1. From the Project Browser right-click Model and select Add General MDL Entity > Sensor, or
right click Sensor from the toolbar.
DY({MODEL.m_door.idstring},{MODEL.m_car.idstring},{MODEL.m_car.idstring})
The DY function accepts three markers as arguments. It returns the Y distance of the first marker
from the second marker in the third marker's reference frame. In this case, the first marker is
the maker labeled Door Lock Mark, which belongs to the Car Door Body. The second and the third
marker is Car Body Lock Mark, which belongs to the Car Body.
5. From the Compare To tab, specify 0.0010 for Value and 0.0001 for Error.
6. Under Respond if, select Signal is less than VALUE + ERROR.
7. From the Response tab, activate the Return to command file check box.
Templates
To simulate the door lock, you need a fixed joint between the door and the car body. The fixed joint
needs to be activated with the sensor. The activation of the joint and the deactivation of the sensor can
be done using a sequential simulation operation.
1. From the Project Browser right-click Model and select Add General MDL Entity > Template,
or right click Template from the toolbar. Add a template to the model and label it Lock Fix
Joint.
2. From the Properties tab of the template, under Type:, select Write text to solver input deck.
3. Type in the following definition of the fixed joint in XML format in the template are of the panel:
<Constraint_Joint
id = "1001"
type = "FIXED"
i_marker_id = "{the_model.m_door.idstring}"
j_marker_id = "{the_model.m_car.idstring}"
/>
This defines the fixed joint between the two markers Door Lock Mark and Car Body Lock Mark.
4. From the Project Browser, right-click Model and select Add General MDL Entity > Template to
add another template.
5. Specify the label as Seq Sim Commands.
6. From the Properties tab of the template, under Type, select Write text to solver command
file.
7. Below are XML Commands for the sequential simulation. Enter the following blocks of XML
commands in the template area of the panel:
<Deactivate
element_type = "JOINT"
element_id = "1001"
/>
<Simulate
analysis_type = "Transient"
end_time = "1.0"
print_interval = "0.001"
/>
<Activate
element_type = "JOINT"
element_id = "1001"
/>
<Deactivate
element_type = "SENSOR"
element_id = "{the_model.sen_0.idstring}"
/>
<Param_Transient
integrator_type = "VSTIFF"
/>
<Simulate
analysis_type = "Transient"
end_time = "2.5"
print_interval = "0.001"
/>
<Stop/>
These set of XML blocks define a sequential simulation operation as specified in the steps below:
d) Deactivate Sensor.
e) Change the Integrator Type to VSTIFF.
f) Simulate for 1.5 seconds.
g) Stop simulation.
8. Save the model once by selecting Export > Solver Deck from File menu.
9. From the Run panel, click the file browser next to Save and run current model and specify a name
for the solver XML file.
10. Click Run to run the model in MotionSolve.
11. Once the run is complete, click Animate to animate the simulation results.
Theory
You can submit ADAMS dataset language files (ADM and ACF) directly to MotionSolve, thus avoiding
manual translation. The ADAMS model is first automatically translated into the MotionSolve XML format
and then it is solved. If the ADAMS model has a flexible body represented by the MNF and MTX files,
the MotionView Flexprep utility will be used to generate an H3D flexible body file (using the MNF file).
This H3D flexbody file is the MotionSolve equivalent of the ADAMS MNF and MTX files. It holds the mass
and inertia properties, as well as the flexibility properties which allow the body to deform under the
application of loads. The deformation is defined using a set of spatial modes and time dependent modal
coordinates.
Process
In this tutorial, an ADAMS single cylinder engine model (ADM and ACF) is provided. To improve the
accuracy of the model responses, the connecting rod is modeled as a flexbody (MNF and MTX). This
chapter deals with transient analysis of this single cylinder engine model using MotionSolve.
We will modify the ACF file to include an argument that would generate a flexbody H3D file. MotionSolve
internally calls OptiStruct, which generates the H3D flexbody file. The ADM and ACF is translated into
MotionSolve XML format and solved. MotionSolve outputs the results H3D file, which can be loaded
in HyperView for animation. In HyperView, external graphics (for piston and crank) can be added for
visualization.
MotionSolve supports most of the ADAMS statements, commands, functions, and user subroutines.
Refer to the MotionSolve User's Guide help for additional details.
Tools
Copy the following files, located in the mbd_modeling\motionsolve folder, to your <working
directory>:
• single_cylinder_engine.adm
• single_cylinder_engine.acf
• connecting_rod_flex_body.h3d
• Flexible_body.mnf
• Flexible_body.mtx
• piston.h3d
• crank.h3d
Note: Below is a table listing the flexbody files in Adams and the equivalent files for
MotionSolve:
3. From the toolbar, click the arrow next to the Open Session icon, , and select Open document ,
FLEX_BODY/1, H3D_FILE=connecting_rod_flex_body.h3d
Figure 86:
5. From the toolbar, click Save Document and save the file as single_cylinder_engine.acf to
your <working directory>.
Note: The connecting_rod_flex_body.h3d file that has been used in this tutorial
is generated using the FlexPrep utility in MotionView. Refer to the MotionView User's
Guide for more information on converting an ADAMS MNF file into a MotionView H3D
flexbody.
Note: Remember to select the crank.h3d file in the Add Object from browser and
attach it to Crank using the expansion button.
10. Click Contour on the toolbar. From the Result type drop-down menu, select the data type that
should be used to calculate the contours.
11. Select a data component from the second drop-down menu located below Result type.
Note: If you select Mag (Magnitude), the results system is disabled (since magnitude
is the same for any coordinate system).
Note: In the Add Object from browser, you can directly select a wavefront file (*.obj)
from ADAMS to add graphics. Whereas, if you have a Parasolid file (*.x_t) from
ADAMS, use the Tools menu option Import CAD or FE in MotionView to generate an
H3D file. You can then use this file to add the graphics.
Figure 87:
Theory
HyperStudy allows you to perform Design of Experiments (DOE), optimization, and stochastic studies
in a CAE environment. The objective of a DOE, or Design of Experiments, study is to understand how
changes to the parameters (design variables) of a model influence its performance (response).
After a DOE study is complete, approximation can be created from the results of the DOE study. The
approximation is in the form of a polynomial equation of an output as a function of all input variables.
This is called as the regression equation.
Note: The goal of DOE is to develop an understanding of the behavior of the system, not to
find an optimal, single solution.
HyperStudy can be used to study different aspects of a design under various conditions, including non-
linear behavior.
Tools
In MotionView, HyperStudy can be accessed from
• From the Menu bar, select Applications >HyperStudy
You can then select MDL property data as design variables in a DOE or an optimization exercise. Solver
scripts registered in the MotionView Preferences file are available through the HyperStudy interface to
conduct sequential solver runs for DOE or optimization.
Figure 88:
Copy the files hs.mdl and target_toe.csv, located in the mbd_modeling\doe folder, to your <working
directory>.
In the following steps, you will create a study to carry out subsequent DOE study on a front SLA
suspension model.
Figure 89:
While performing a Static Ride Analysis, you will determine the effects of varying the coordinate
positions of the origin points of the inner and outer tie-rod joints on the toe-curve.
Or, from the menu bar, select File > Open > Model.
3. Select the file model hs.mdl, located in your <working directory>, and click Open.
4. Review the model and the toe-curve output request under Static Ride Analysis.
5. From the Applications menu, select HyperStudy.
HyperStudy is launched. The message "
Establishing connection between MotionView and HyperStudy
" is displayed.
6. Start new study using one of the following ways:
• From the Welcome page, click the New Study icon, .
• From main menu, select File > New. The HyperStudy - Add Study dialog is displayed.
Figure 90:
Figure 91:
9. Model data.
Please note that following details are automatically filled when you define the model (previous
step).
a) Under Active, check the box to activate or deactivate the model from study.
b) The label of model entered in previous step.
c) The variable name of model entered in the previous step.
d) The model type selected in previous step.
e) Point to the source file (here model file is sourced from MotionView through the MotionView –
HyperStudy interfacing).
f) Enter a name for the solver input file with the proper extension (for MotionSolve .xml) and
select the solver execution script MotionSolve - standalone ( ms).
10. Create design variables.
a) Click Import Variables to specify the design variables for the study.
b) The Model Browser window opens in MotionView, allowing you to select the variables
interactively.
c) Select the following from the Browser using the Model Parameter Tree dialog:
d) Click Done.
e) Click Next to go to Define Design Variables.
11. Define design variables.
a) From the Define design variables tab, edit the upper and lower bounds of the design
variables according to the following table.
Figure 93:
b) This step also includes definition of other properties to the design variables. The options
Details and Distributions specify variations of design variables in the range specified. The
option Link Variables is used to link different design variables through a mathematical
expression.
c) Click on each tab to observe these options.
d) Right click on the column header row to view more options that you may want to add.
Figure 94:
d) Click the ellipses, …, in the Expression cell of Response table to launch the Expression
Builder.
Note: You can move the cursor over the function to display the function help. For
this exercise, the response function requires two Data Sources:
• The elements of Data Source 1 contain actual data points of the toe curve
from the solver run for the nominal configuration.
• The elements of Data Source 2 contain data points from the target curve.
e) Click the Data Sources tab to source the data from the files.
15. Data Source 1
a) Click to add a new data source using the solver output file.
b) Click the ellipses, …, in the File cell of Data Source table data to launch the Data Source
Builder: Data Source 1 (ds_1) dialog box.
c) Click the file browser button, , and select the file m_1.mrf from <working directory>
\approaches\nom_1\run__00001\m_1\.
d) This enables the Type, Request and Component fields.
e) From the Type drop-down menu, select Expressions.
f) From the Request drop-down menu, select REQ/70000033 toe-curve.
g) From the Component drop-down menu, select F2.
You have now selected the toe curve data from the solver run as the data elements for Data
Source 1.
h) Click OK.
16. Data Source 2
a) Create a Data Source to hold the data elements from the target toe curve.
b) Click Add Data Source to add a new data source using a reference file.
c) Click the … in the File cell of the Data Source 2 table data to launch the Data Source Builder:
Data Source 2 (ds_2) dialog box.
d) Click the file browser button, , and select the file target_toe.csv, located in your
<working directory>\.
• Set Type to Unknown and Request to Block 1.
• From the Component drop-down menu, select Column 1.
• Click OK.
17. In the Expression field, create the following expression:
sum((ds_1-ds_2))^2)
This expression evaluates the sum of the square of the difference between the “actual toe change”
values (from solver run) and the “targeted toe curve” (from imported file). In the next tutorial,
MV-3010, we will use HyperStudy to minimize the value of this expression to get the required
suspension configuration.
Figure 100:
18. Click Evaluate expression to verify that the expression is evaluated correctly. You should get a
value of 16.289.
19. Click OK to close the Expression builder and hit the Evaluate button.
a) If you do not encounter any error messages and were able to successfully extract the
response for the nominal run, click Next to go to Post Processing.
b) Observe the table with the design variable values used for the nominal run and other tabs
with the post-processing options.
c) Click Next to go to Report.
d) Observe various reporting formats available. The images and data captured during the post-
processing can be exported in any of the formats provided on Report page.
20. From the File menu, select Save As….
21. Save this study set-up as Setup.xml to your <working directory>\.
Figure 101:
Or
b) From the Toolbar, click the Add Approach button to display the HyperStudy - Add dialog.
Figure 102:
Figure 103:
Figure 104:
Note: Selecting any mode from the list shows all possible options in the
Parameters panel area on the left side of GUI.
b) Click the Levels tab to see the design variables and number of levels.
Figure 105:
c) Click the Interaction tab to observe that it is not applicable since all interactions are
selected by default for a full factorial run.
Figure 106:
Note: Options which are not applicable will be grayed out or a message will be
shown.
Design variable values used under each experiment can be seen under the Evaluation Data tab.
The last column corresponds to the response value from each run. The values gets populated once
the run is completed.
Figure 107:
Once all the runs are finished, the tasks table gets filled up with the status for each run
(Success/Fail).
b) In the present DOE study, all runs are successfully completed. Click Next to go to Post
Processing.
8. Viewing Main Effect and Interaction plots:
The post-processing section has variety of utilities to helps user to effectively post process results.
Summary tab of Post processing page will provide a summary of design along with responses.
The New Generation HyperStudy allows you to sort data by right-clicking on the column heading
and selecting the options from context menu.
The options to post-process are available in other tabs. The main effects can be plotted by
selecting the Linear Effects tab.
9. Main Effects
a) Click the Linear Effects tab to open the main effects plot window. From the Channel page,
select Variables and Responses for which main effects need to be plotted. Press the left
mouse button and move over the variable or responses list for multiple selection.
b) Select all controlled variables and responses to plot the main effect plot. This plot shows the
effect of each parameter on the response.
10. Interactions
An interaction is the failure of one variable to produce the same effect on the output response at
different levels of another input variable. In other words, the strength or the sign (direction) of an
effect is different depending on the value (level) of some other variable(s). An interaction can be
either positive or negative.
Interactions can be plotted from the Interactions tab following the above procedure.
This displays the interaction plot for these two variables only.
Figure 109: Controlled design variable plot for “Otr_tierod_ball_jt-left-z” & “Inr_tierod_ball_jt-left-z”
interaction
Step 3: Approximation
System response is approximated by using various curve fitting methods. An approximation for the
response with the design variables variation is calculated using the data from above DOE study. The
accuracy of the approximation can be checked and improved.
1. Adding an approximation.
a) Right-click in the Explorer browser area and from the context menu, click Add to display the
Add Approach dialog.
Figure 110:
Figure 111:
Figure 112:
Figure 113:
The residual values can be used to determine which runs are generating more errors in the
regression model.
The Trade-off tab shows the plots of the main effects vs. response from the approximation.
Figure 115:
r) From the toolbar, click the Save icon, , to save the study.
Note: All study files will be saved in the study directory with the folder names
that are the same as the tree varnames. For example, nom_1, doe_1, and fit_1.
Theory
In general, an optimization problem consists of:
• The design constraints
• The objective function
• The design variables
Design variables change during optimization. The design variables always have a certain range within
which they can be modified. Typical examples of design variables are thickness of shell elements, shape
vectors, and masses.
The changes in the design variables cause some change in model responses. Such responses
can become either objective function or design constraints. Examples of such responses include
displacements and forces.
The response to be minimized or maximized becomes the objective function, while the rest of the
responses that need to be within a certain tolerance range become constraints. Only one response can
be defined as objective function.
HyperStudy can be used to set-up and perform an optimization study on a MotionView model. You can
also use HyperStudy to perform optimization studies involving both linear and non-linear CAE analysis
as well as perform optimization of mathematical equations using Templex. HyperStudy creates the input
parameter files using Templex and provides iterative changes to them during the optimization process.
HyperStudy uses HyperOpt (a general purpose, wrap around software) as the optimization engine to
perform optimization, in conjunction with both linear and non-linear CAE analysis software. HyperOpt
uses a robust sequential response surface methodology for optimization.
The files needed for this tutorial are hs.mdl, target_toe.csv (used in tutorial MV-3000); Setup.xml
saved in tutorial MV-3000 and the nom_run folder created in tutorial MV-3000.
These files should be in the <working-directory> that was used in tutorial MV-3000.
Note: If you copy the Setup.xml file from the above location, the path in the <Folder> tag
in the file needs to be edited to point to your <Working directory>.
In the following steps you will perform an optimization study on a front SLA suspension model and
determine the optimum coordinate positions of the inner and outer tie-rod points while trying to achieve
a target toe curve. The baseline model will then be compared with the optimized model.
Figure 116:
a)
Click to launch the HyperStudy - Add Objective dialog box.
Figure 117:
b) Accept the default label and variable names and click OK.
In this exercise, minimize the Sum of Squared Error response function to obtain optimum
values for the design parameters: the Y and Z coordinate positions of the inner and outer tie-
rod points.
c) Check to make sure that the type is set as Minimize from the drop-down menu.
d) Check to make sure that the Evaluate From option is set to Solver.
Figure 118:
10. There aren't any constraints and unused responses in the design, so click Apply and then click
Next to go to Specifications.
Accept the default Optimization Engine: Adaptive Response Surface Method and click Apply and
Next. The Maximum iterations and Convergence criteria are specified in the same dialog.
11. Click Apply and Next to go to Evaluate.
12. Click Evaluate Tasks to start the optimization.
MotionSolve is launched sequentially and the HyperOpt engine attempts to find a solution to the
problem.
Once the optimization is complete, an Iteration table is created with status of each run. The
present study took nine iterations to achieve the target. Browse through the other tabs of this
page to get more understanding of the iteration history.
13. Click the Iteration Plot 2D tab.
14. From the list on the right side of the GUI, select the Objective function named Objective_1.
This plots the objective function value against the iterations.
In this panel, you can see the plots variations in the values of the objectives, constraints, design
variables, and responses during different design iterations. The Iteration History Table displays the
same data in a tabular format.
7. Use the Build Plots file browser, and select the file target_toe.csv, located in the <working
directory>.
8. For X-axis data, select:
a) Type = Unknown
b) Request = Block 1
c) Component = Column 1
9. For Y-axis data, select:
a) Type = Unknown
b) Request = Block 1
c) Component = Column 2
10. Click Apply.
11. Using the file browser on the Build Plots panel, select the file <working directory>\approaches
\nom_1\run__0001\m_1\m_1.abf.
12. For X-axis data, select:
a) Type = Expressions
b) Request = REQ/70000033 toe-curve
c) Component = F2
13. For Y-axis data, select:
a) Type = Expressions
b) Request = REQ/70000033 toe-curve
c) Component = F3
14. Click Apply.
15. Plot another curve from the file.
<working directory>\approaches\opt_1\run__00006\m_1\m_1.abf using steps 11-14
You should end up with a session looking like the one shown below. Notice the optimized toe-
curve.
You may also overlay the animation of the optimal configuration (run 6) over the nominal run.
Notice the toe angle differences.
16. Save the session as opt_toe.mvw.
The image below illustrates the geometry and the values that you need.
Figure 121:
The above command requires the msolve module be in your computer path. Assuming the above is
successful, you have imported the msolve names into the current namespace. This means you have
access to all the classes and functions defined in msolve and can start creating the bouncing ball case.
Creating a Model
To create the pendulum mechanism, you must first create a model.
The above command requires the msolve module be in your computer path. Assuming the above is
successful, you have imported the msolve names into the current namespace. This means you have
access to all the classes and functions defined in msolve and can start creating the bouncing ball case.
3. You can now create the ground part by using the Part class and specifying the ground Boolean
attribute as 'True':
Creating Markers
Next, you can create markers on the ground part. A marker is defined by a geometric point in space
and a set of three mutually perpendicular coordinate axes emanating from that point. It can be used as
a reference frame of the part that it belongs to.
You can similarly create the ball by first creating a part with mass and then creating a sphere
located at the cm (center of mass) of the part. Inform the solver of the mass and cm of the part
unless you are creating a ground part.
(3)
2. Call Sforce to calculate the contact force as the ball moves. The input function should be a
MotionSolve expression and the z axis of marker j defines the direction that the force applies.
In [11]: input_function =
"IMPACT(DZ({I}, {J}, {J}),VZ({I}, {J}, {J}),{G},{K},{E},{C},{D})"
.
format( I=marker_i.id,J=marker_j.id, K=5e9, G=0.00, E=1.0, C=0.8e5, D=0.0 )
contact_force = Sforce(i = marker_i.id, j = marker_j.id,
type=
"TRANSLATION"
, function = input_function)
You can also create a request. Requests define output channels in MotionSolve and are written to
MotionSolve output files so that they may be used for plotting and signal processing by HyperGraph.
Requests can be defined using runtime expressions, built-in functions (MOTION, FORCE, FIELD, and so
on), or user-written functions.
1. Create a displacement request using the predefined "DZ" method and then create another request
to track the contact force:
2. Call Sforce to calculate the contact force as the ball moves. The input function should be a
MotionSolve expression and the z axis of marker j defines the direction that the force applies.
In [13]: input_function =
"IMPACT(DZ({I}, {J}, {J}),VZ({I}, {J}, {J}),{G},{K},{E},{C},{D})"
.
format( I=marker_i.id,J=marker_j.id, K=5e9, G=0.00, E=1.0, C=0.8e5, D=0.0 )
contact_force = Sforce(i = marker_i.id, j = marker_j.id,
type=
"TRANSLATION"
, function = input_function)
2. In the following example, you are extracting the model.despRequest from the run container. The
purpose is to have a convenient data structure for extracting time varying results.
In [15]: dz=run.getObject(model.dispRequest)
3. Use the dz object to plot the displacement along the global z axis, using the matplotlib module
available in IPython notebook. The plot is displayed inline. You can see how the magnitude of
bouncing changes as time goes.
In [16]: %matplotlibinline
frommatplotlibimport pyplot
pyplot.plot(dz.times, dz.getComponent(1))
pyplot.xlabel('Time(s)')
pyplot.ylabel('Displacement(m)')
pyplot.show()
Figure 122:
The bouncing magnitude decreases each time the ball hits the ground because a damping exists in
the definition of contact force.
If you are running this tutorial as IPython notebook, you can interactively execute each code cell by
clicking SHIFT-ENTER. The output of the Python code (if any) will be displayed and the execution will
jump to the next cell.
The image below is a graphical representation of the system that you are going to build.
Figure 123:
A rigid body is suspended by a mass-less wire and is connected to the ground via a hinge joint. The
only force acting on the system is gravity, directed along the negative vertical direction. The simulation
shows a part swinging from its initial resting position. There is no friction force in the joint, nor any
type of energy dissipating force acting on the part, therefore the ball reaches 180 degrees of angular
displacement for each full swing.
The above command requires the msolve module to be in your computer path. Assuming the above
is successful, you have imported the msolve names into the current namespace. This means that
you have access to all classes and functions defined in msolve and you can start creating the simple
pendulum.
Creating a Model
To create the pendulum mechanism, you must first create a model. A model is nothing but a container
that serves as a parent for all the entities. The model class takes a keyword argument to specify the
output file name for MotionSolve. You can use the name 'pendulum'.
MotionSolve creates a series of output files (such as .mrf, .abf and .h3d) using pendulum as the root
name.
2. Since you want to model in mmks, modify the length property of the units and assign a value of
"MILLIMETERS". You can perform a simple direct assignment:.
In [4]: units.length="MILLIMETER"
3. Similarly, you can create the gravitational acceleration field with the Accgrav class.
In [5]: gravity=Accgrav(kgrav=-9810)
Notice the result of the Accgrav creation is stored in a variable called gravity. That is the name
that appears to the left of the equal sign. This is now a Python variable in the current namespace
and, as such, can be used anywhere in the scope.
Note that in msolve class names, use the CapWords convention and be aware that you can use the
Python help system to learn about each msolve class, its use, and properties. Complete the steps below
as an example.
4. To interact with the Accgrav class, call the help ( ) function with the class name as the input
argument.
In [6]: help(Accgrav)
Help on class Accgrav in module msolve.Model:
class Accgrav(Force)
| Accgrav defines the acceleration due to gravity along the global X, Y, and Z
directions.
|
| Method resolution order:
| Accgrav
| Force
| msolve.Base.SolverObject
| __builtin__.object
|
| Methods defined here:
|
| sendToSolver(self)
| Send the object to the solver
|
| setSolverValue(self, name, value)
| Set the property 'name' to 'value' between simulations
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| igrav
| Gravity in the global X direction
| Type=Double, Optional, Default=0
| Modifiable during simulation
|
| jgrav
| Gravity in the global Y direction
| Type=Double, Optional, Default=0
| Modifiable during simulation
|
| kgrav
| Gravity in the global Z direction
| Type=Double, Optional, Default=0
| Modifiable during simulation
A lot of information is displayed when the help function is called. The most important piece of
information is the description of the class and its properties. For example, data descriptors are
defined in the code below:
igrav
Gravity in the global X direction
Type=Double, Optional, Default=0
Modifiable during simulation
In msolve, creating a class instance always returns an object. This gives you the ability to
reference the object using its name, gravity in this case. You can use gravity and its properties
anywhere in the model. For example, you can modify its properties during the model building
phase, or between MotionSolve simulations. The benefits of this approach are illustrated later in
this tutorial.
As a general rule, it's useful to store the objects being created using local variables, especially
if they will be modified or referenced elsewhere. At this point, you can proceed with the model
creation.
5. Create the ground part, use the Part class, and specify the ground Boolean attribute as 'False'.
In [7]: ground=Part(ground=True)
Defining Points
Some models in MBS are defined using points. Points are a special auxiliary object with an x, y, z
location and a handful of convenient methods. They are a powerful way to define a mechanism and can
be used anywhere in the model where an X,Y,Z quantity is needed (for example, to position a part or
position a marker origin).
In this example, use points to locate various objects (such as markers) in the three dimensional space.
You can use points when defining marker locations and orientations.
To create a point at the global origin, do not include an argument, as not having an argument in the
Point class signifies that the x,y,z coordinates are set to the default values of 0,0,0. Issue the following
command:
In [8]: p0=Point()
Creating Markers
You can use this point to locate the origin of the ground marker. A marker is defined by a geometric
point in space and a set of three mutually perpendicular coordinate axes emanating from that point.
In the marker class, the property qp corresponds to the location of the marker origin in the body
reference frame. Since you are using ground as the body, the qp propery is the location of the marker in
the global reference frame. Use the zp, xp method to orient the Z and X axes.
1. In the command below, supply a point in space used to orient each of the two axes, the third
being automatically computed as an orthogonal right handed coordinate system.
2. Now you can create the pendulum body. It's a rigid part with a mass of 2kg and some nominal
inertia properties.
3. Optional: If you type part. and the TAB key in a code cell, you will be able to see all the functions
and properties applicable to part as a drop down list.
In [11]: part.validate()
Part/2
ERROR:: Mass is specified but cm is not specified.
ERROR:: There are no markers on this part.
Out[11]:
False
In [12]: p1 = Point(100,0,0)
# create the marker as the part.cm
# note that the '.' operator allows us to define a the 'cm' property of the part
object.
# the marker will be positioned at (100,0,0), the X axis is pointing towards the
point (200, 0,0)
# and the z axis points to (200, 100, 0)
A requirement of the revolute joints is that the i and j markers need to be coincident and need to have
their Z axes properly aligned.
You will also create a request. Requests define output channels in MotionSolve and are written to
MotionSolve output files so that they may be used for plotting and signal processing by HyperGraph.
Requests can be defined using runtime expressions, built-in functions (MOTION, FORCE, FIELD, and so
on,) or user written functions.
In this case, you can create a force request using the predefined "FORCE" method and create another
request tracking angular displacement using the AX MotionSolve runtime function. AX measures the
angular displacement in radians between two markers.
2. Call Sforce to calculate the contact force as the ball moves. The input function should be a
MotionSolve expression and the z axis of marker j defines the direction that the force applies.
In [15]: input_function =
2. You can easily modify the part mass property by changing its value with a direct assignment:
In [17]: part.mass= 12
3. At this point you can run another simulation, starting from the end of the previous analysis. To do
that, simply issue a new simulate command and specify an end time of four seconds. Note that
this simulation is done with the new part mass, so you should be able to see the effect of that in
the joint reaction forces.
4. In the following command, you are extracting the force_req from the run container. The purpose is
to have a convenient data structure for extracting time varying results.
5. You can use the force object to plot the longitudinal reaction force Fx. To do so, you are using the
matplotlib module available in the IPython notebook. The plot is displayed inline. You can see how
the mass modification at time = 2 sec affects the magnitude of the reaction force, generating a
peak of 350N.
6. Similarly, you can plot the rotation angle. A generic runtime expression was used in the angular
displacement request, so you need to get the right component that corresponds to the AY (angle
about the Y axis of the marker j of the angle request.
The angular displacement is a simple harmonic function and the pendulum reaches 180 degrees
because there are no dissipative forces such as viscous friction in the joint. Note that the
frequency of oscillation is governed by these equations:
(4)
(5)
As visible from the plot above, the mass swings with a frequency of about 1.5Hz. The
generateOutput() function called below creates a MotionSolve *.plt file and H3D animation files
for visualization in HyperView and HyperView Player.
In [22]: model.generateOutput()
In conclusion, you have learned how to create a simple pendulum model, run transient simulations, and
plot results.
If you are running this tutorial as IPython notebook, you can interactively execute each code cell by
clicking SHIFT-ENTER. The output of the Python code (if any) is displayed and the execution jumps to
the next cell. If you want to run it, you also need to make sure that the file slotted_link.fem is in the
folder.
The above command requires the msolve module to be in your computer path. Assuming the above is
successful, you have now imported the msolve names into the current namespace. This means that you
have access to all the classes and functions defined in msolve and you can start creating the bouncing
ball case.
Creating a Model
To create the pendulum mechanism, you must first create a model. A model is nothing but a container
that serves as a parent for all of the entities.
2. Similarly you can create the gravitational acceleration field. Notice that the gravity is set to zero:
it would not affect the motion of the slotted slider.
3. You can now create the ground part. To do that, use the Part class and specifying the ground
Boolean attribute as 'True'.
Adding Parts
Next, you can create four parts representing the link, cam, pin, and slotted link. You can also specify
the mass, initial property, and the center of mass for the part. This information would not be imported
to MotionSolve from CAD or FEM file automatically.
Importing Geometry
Now you can import geometry for the part. To do so, create four external instances. The class External
is created to help users import a CAD file or an FEM file. If the file imported has multiple components,
you can extract them one-by-one by specifying the 'element' property. When the CAD file is imported,
you can improve the mesh by increasing the value of 'refinement_level'. The example below shows how
external instances are created in this case:
element=["Link"], refinement_level = 0)
pin_geo = External(rm = pin_geo_marker, file ="slotted_link.fem",
element=["Pin"], refinement_level = 0)
cam_geo = External(rm = cam_geo_marker, file ="slotted_link.fem",
element=["Cam"], refinement_level = 0)
slotted_link_geo = External(rm = slotted_link_geo_marker, file ="slotted_link.fem",
element=["Slotted_Link"], refinement_level = 0)
Adding Joints
The next step is to create the joints between different parts. Two fixed joints are created: one between
the pin and the link, and the other connecting the link and the cam. For a fixed joint, the i marker and j
marker should be coincident with their x,y,z axis aligned.
## Link-Cam-Fix at Link cm
link_cam_i = link.cm
link_cam_j = Marker(part = cam, qp = link.cm.qp)
link_cam_fix = Joint(
type ="FIXED", i = link_cam_i, j = link_cam_j)
2. The slotted link is only allowed to slide along global x-axis. Here, create a translational joint:
3. You can impose a revolute motion on the pin-cam-link entity. To do so, you first need to create a
revolute joint that rotates along the global y axis.
Adding Motion
The motion can be created by creating an instance of Motion in msolve. You can change the pattern
of motion by specifying the property 'function'. The property 'function' should be a MotionSolve
expression.
Adding Contact
The last step is to create contact between the geometries that you imported. Two Poisson contacts are
created here: one between the cam and slotted link, and the other between pin and slotted link.
In [13]: cam_slotted_contact =
Contact(igeom=cam_geo,jgeom=slotted_link_geo,type="POISSON",
restitution_coefficient=0.5,penalty=1e5)
pin_slotted_contact = Contact(igeom=pin_geo,jgeom=slotted_link_geo,type="POISSON",
restitution_coefficient=0.5,penalty=1e5)
Creating Requests
Before running the model, create requests that track the contact force and the penetration depth. The
result can be plotted using pyplot.
In [14]:#forceRequest = Request(f2="FX({I})".format(I=slotted_link_geo_marker.id))
forceRequest = Request(f1="CONTACT({ID},{JFLAG},{COMP},
{RM})".format(ID=cam_slotted_contact.id,
JFLAG=1,COMP=1,RM=0),
f2="CONTACT({ID},{JFLAG},{COMP},
{RM})".format(ID=pin_slotted_contact.id,
JFLAG=1,COMP=1,RM=0))
depthRequest = Request(f1="CONTACT({ID},{INDEX},
{RM})".format(ID=cam_slotted_contact.id,
INDEX=1,RM=0),
f2="CONTACT({ID},{INDEX},
{RM})".format(ID=pin_slotted_contact.id,
INDEX=1,RM=0))
You can also generate an output file that can be imported into MotionView for animation.
%matplotlib inline
force = run.getObject(forceRequest)
depth = run.getObject(depthRequest)
from matplotlib import pyplot
pyplot.subplot(2,1,1)
pyplot.plot(force.times, force.get
Component(0),'r',force.times, force.getComponent(1))
pyplot.title("Contact Force Magnitude")
pyplot.xlabel("Time(s)")
pyplot.ylabel("Contact Force (N)")
pyplot.grid(True)
pyplot.legend(["Cam-Slotted Contact","Pin-Slotted Contact"],loc="upper
left",prop={'size':8})
pyplot.subplot(2,1,2)
pyplot.plot(depth.times, depth.getComponent(0),'r',depth.times,
depth.getComponent(1))
pyplot.title("Maximum Penetration Depth")
pyplot.xlabel("Time(s)")
pyplot.ylabel("Penetration Depth (m)")
pyplot.grid(True)
pyplot.legend(["Cam-Slotted Contact","Pin-Slotted Contact"],loc="upper
left",prop={'size':8})
pyplot.subplots_adjust(hspace=0.5)
pyplot.show()
Figure 126:
You can import the H3D file generated by this tutorial into MotionView for post-processing. The
animation below illustrates the motion of the slotted link when the cam rotates.
Figure 127:
A class is a blueprint, or template, that allows you to create a higher level entity and treat it just like
any other MotionSolve object.
In this example, you will combine a series of MotionSolve entities into a class called LuGre to define a
new modeling element that exhibits new behavior. This process is called aggregation and MotionSolve
provides a special composite class to represent such objects.
Composite is a special class that allows you to aggregate entities, such as parts, markers, forces,
differential equations, and other MotionSolve primitives. A composite class object behaves just like any
other solver object except it is a collection of entities conveniently packaged together. They behave as
atomic entities and can be instantiated multiple times.
The advantage of using the composite class is that the LuGre object inherits behaviors from the base
class. In particular, you will be able to modify the LuGre object at run-time, just like you would issue a
modify command on any other MotionSolve primitive object, such as a part or a marker. The example
below illustrates how you can create your own composite class. First, you'll examine the LuGre friction
model.
Figure 128:
• = Bristle stiffness
• = Bristle damping
• = Viscous coefficient
•
Stribeck factor
•
The normal force
• Coulomb friction
• Static Friction
•
•
ODE defining bristle deflection
The above command requires the msolve module to be in your computer path. Assuming the
above is successful, you have now imported the msolve names in the current namespace. This
means that you have access to all the classes and functions defined in msolve and you can start
creating the LuGre class and supporting model.
Below is the entire implementation of the class. Each section will be reviewed in the paragraphs
following the code cell.
# Set topology
self.friction.i =self.joint.iself.friction.j =self.joint.jself.im.setValues
(body=self.joint.i.body, qp=self.joint.i.qp, zp=self.joint.i.zp)
self.request.setValues (i=self.im, j=self.joint.j, rm=self.joint.j)
def validateSelf(self, validator):
validator.checkGe0 ("vs")
validator.checkGe0 ("mus")
validator.checkGe0 ("mud")
validator.checkGe0 ("k0")
validator.checkGe0 ("k1")
validator.checkGe0 ("k2")
if self.mud > self.mus:
msg = tr("Mu dynamic({0}) needs to be smaller than Mu static ({1})",
self.mud,self.mus)
validator.sendError(msg)
2. Now that the class has been defined, you need to to fill the implementation details. The LuGre
friction uses a single component force between two bodies, and a first-order differential equation
that models the average deflection of the bristles as a function of slip velocity, coefficients of
friction, and normal force. First you'll work on the Single Component Force. The goal of the Sforce
function (normally called SfoSub) is to compute and return the scalar value of the friction force.
The three component depicted here are computed separately in the force function.
z = DIF(self)
v = VZ(i,j,j,j)
p = -(v/vs)**2
g = (fc + (fs - fc) * math.exp(p))/k0
def smooth_fabs(x):
returnmath.fabs(x) # temp solution
if iflag or math.fabs(g) <1e-8:
return v
else:
return v - smooth_fabs(v) * z / g
def lugre_force (self,id, time, par, npar, dflag, iflag):
"Friction Force user function"
i = self.joint.i
j = self.joint.j
diff = self.diff
k0 = self.k0
k1 = self.k1
k2 = self.k2
v = VZ(i,j,j,j)
z = DIF(diff)
zdot = DIF1(diff)
The composite class LuGre is inherited from the built-in composite class. You have to write two
special methods, createChildren and setChildDataValue, to define the behavior of this class.
You can also optionally write a validate method, validateSelf.
An optional method called validateSelf can be defined. This method checks the input to ensure
that the data provided to the LuGre class interface is physically meaningful. For example, by
verifying that the static friction coefficient is larger than the dynamic friction coefficient.
After the methods described above, there are two additional functions. These are the Sforce
and Diff user written subroutines. Note that these functions are created directly within the
class definition. The advantage of doing this is to make the class properties available to the
implementation of the subroutines.
The Sforce subroutine computes the three components of the friction Sforce, as described in the
image below.
Figure 129:
Note that the function's first argument is self because Sforce and Diff user written subroutines
are Python callable class methods. Also, note that the signature of the Sforce function is in the
familiar form (id, par, npar, and so on) but you are not actually unpacking the parameters, as
there is no need to pass anything to the subroutine.
You are in fact accessing the properties of the LuGre instance by using the dot operator on the
instance itself.
Similarly, you can define the differential equation. This also accesses the LuGre properties directly.
Creating a Model
Now that you have completely defined the LuGre class and implemented the two methods (Sforce and
Diff), you have to create a suitable model for testing.
You can use a simple friction element defined between two bodies on a sliding block. The sliding block is
constrained by a translational joint and a forcing function acts upon it.
You can study the effect of changing the Static Friction Coefficient μs on the computed friction force by
modifying it between simulations.
The model is created inside a function, called _slidingblock, in the code cell below. This is done purely
for convenience.
In [2]:
################################################################################
# Model definition #
################################################################################
def sliding_block ():
"""Test case for the LuGre friction model
Slide a block across a surface.
The block is attached to ground with a translational joint that has
LuGre friction
"""
model = Model ()
Integrator (error=1e-5)
Output (reqsave=True)
# Location for Part cm and markers used for the joint markers
qp = Point (10,0,0)
xp = Point (10,1,0)
zp = Point (11,0,0)
Note that the creation of the LuGre friction is done by calling one single line:
All you need to do is pass the Translational Joint, joint, to the LuGre class instantiation.
All of the properties that are used in the calculation of the Friction Force default to the values
defined in the class interface. You can, of course, pass different values to the LuGre class but for
now, you will use default values.
2. Test the model and plot some results.
a) Create a model by calling the following function:
model = sliding_block ()
b) Run a 4 second simulation and store the results of the run in an appropriate container:
Now that you have a run container with a series of requests, you can selectively plot some of
the relevant channels, such as the magnitude of the friction force, the block velocity,and its
displacement as a function of time.
3. Import a plotting package:
4. Then, extract some of the data to plot. At this point, you can create a plot object and display three
separate curves.
• The friction force.
• The velocity of the block.
• The block displacement.
plt.subplot(3, 1, 1)
plt.plot(force.times, force.getComponent (3))
plt.title('Friction force')
plt.ylabel('force [N]')
plt.subplot(3, 1, 2)
plt.plot(velo.times, velo.getComponent (3),'r')
plt.title('Block Velocity')
plt.ylabel('velocity [m/s]')
plt.subplot(3, 1, 3)
plt.plot(disp.times, disp.getComponent (3),'g')
plt.title('Block Displacement')
plt.xlabel('time (s)')
plt.ylabel('travel [m]')
plt.grid(True)
plt.tight_layout()
In [7]: plot(model)
Figure 130:
5. To increase the friction static coefficient, set the LuGre to a different value and continue the
simulation for an additional four seconds.
# replot the quantities and observe the changes to the Friction Force
plot(model)
Figure 131:
With the increased , you can see that the forcing function cannot overcome the bristle resistance
and the block is not able to move.
1. Create a C/C++, FORTRAN, Tcl, or Python source file that contains the user-defined modeling
entity.
Refer to the MotionSolve User's Guide for a list of supported solver subroutines and a general
guideline on setting up and using subroutines in your model.
2. Obtain a DLL by compiling and linking your user subroutine(s) for C/C++ or Fortran, or use the
source file directly for Tcl or Python.
MotionSolve supports two separate levels of user DLLs and the algorithm attempts to resolve the
symbols, starting from the most specific library.
1. Element Level DLL (most specific)
Specify the name of the DLL in the modeling element definition.
2. Machine Level DLL
You can create an environment variable called MS_USERSUBDLL and set it to the
DLL file. This environment variable is not defined automatically when MotionSolve is
installed. However, Fortran, and C/C++ DLLs are provided in the installation folder
<installation_directory>\hwsolvers\usersub\subdll\win32\. This allows you to run
some of the test models that use user subroutine DLLs.
Note: The DLL that is loaded is based on the "most specific" rule: number one
overrides number two.
3. Modify the corresponding entity in your multibody model to be "user defined" and point it to your
DLL. This can be done in two ways:
1. By modifying the entity in the MotionView interface.
2. By editing the MotionSolve XML file.
Regardless of the method you select, you will end up with an XML file where one or more entities
are now user defined.
For example, consider the coupler modeling element in the XML file:
<Constraint_Coupler
id = "1"
type = "TwoJoint"
i_marker_id_joint1 = "30603030"
j_marker_id_joint1 = "30602031"
body1_id_joint1 = "30603"
body2_id_joint1 = "30602"
joint_type_joint1 = " "
i_marker_id_joint2 = "30603040"
j_marker_id_joint2 = "30604040"
body1_id_joint2 = "30603"
body2_id_joint2 = "30604"
joint_type_joint2 = " "
usrsub_param_string = "USER(-8.5)"
usrsub_dll_name = "C:/work/testsub.dll">
</Constraint_Coupler>
The usrsub_dll_name argument defines C:/work/testsub.dll as the element level DLL for this
coupler element. Any element can be defined by pointing to a different DLL.
The coupler modeling element in the XML file can also be defined as:
<Constraint_Coupler
id = "1"
type = "TwoJoint"
i_marker_id_joint1 = "30603030"
j_marker_id_joint1 = "30602031"
body1_id_joint1 = "30603"
body2_id_joint1 = "30602"
joint_type_joint1 = " "
i_marker_id_joint2 = "30603040"
j_marker_id_joint2 = "30604040"
body1_id_joint2 = "30603"
body2_id_joint2 = "30604"
joint_type_joint2 = " "
usrsub_param_string = "USER(-8.5)"
usrsub_dll_name = "NULL">
</Constraint_Coupler>
In this case, MotionSolve looks for a machine level DLL as defined by the value of the
MS_USERSUBDLL environment variable.
4. Run MotionSolve, verifying that it picks up the appropriate DLL during simulation.
Copy the model file required for this exercise, Pendu_model.mdl, from the mbd_modeling\motionsolve
to your <working directory>.
4. Add a Displacement motion to the revolute joint between the pendulum body and the ground
body.
5. Click the Properties tab.
9. Click Save and run current model and browse to your <working directory>. Specify the name
as Pendu_model.xml for the MotionSolve input XML file.
10. Confirm that the Simulation type is set to Transient.
11. Specify 1 as the End Time.
12. Click Check to check for any modeling errors.
1. Create an environment variable MS_USERSUBDLL and set the value to the DLL file.
a) For Windows 32-bit platform users, set the value to <installation_directory>\hwsolvers
\usersub\subdll\WIN32\ms_csubdll.dll.
b) Right-click on the My Computer icon. From the Advanced tab, select Environment
variables > New (under User variables).
c) Set Variable name to MS_USERSUBDLL.
d) Set Variable value to <installation_directory>\hwsolvers\usersub\subdll
\win32\ms_csubdll.dll.
Figure 132:
2. With the Pendu_model.mdl from the previous step open in the MotionView model window, go to
the Motions panel, .
3. From the Connectivity tab, check the User-defined properties check box.
4. Click the User-Defined tab and enter USER(100001,5,2) in the text-box.
Figure 133:
Note: To use an element level (specific) DLL/Interpreter function, you can check the
Use local dll and function name check-box and point to the DLL using the folder
icon, .
The string USER(100001,5,2) is used to pass arguments to the MOTSUB user subroutine.
The MOTSUB user subroutine calculates motion using the parameters par1 and par2 in
USER(branch_id, par1, par2) as follows:
motion_val= par1*TIME^par2
8. Click Save and run current model and browse to your working directory. Specify
Pendu_model_usersub.xml for the MotionSolve input XML file.
9. Confirm that the Simulation type is set to Transient.
10. Specify 1 as the End Time.
11. From the Main tab, click Check to check for any modeling errors.
12. After verifying that there are no errors, click Run.
13. In the plot window, plot the results from the ABF file Pendu_model_usersub.abf to overlay the
results on top of the results from the Pendu_model.abf file
14. In the animation window, check the Overlay option on the Load Model panel.
15. Select the file Pendu_model_usersub.h3d using the Load model folder icon .
Figure 134:
17. Open the MotionSolve XML file Pendu_model.xml (saved in step 1) from the working directory.
18. Browse through the XML file to locate the Motion_Joint block.
<Motion_Joint
id = "301001"
label = "Motion 0"
type = "EXPRESSION"
val_type = "D"
expr = "3.142*TIME"
joint_id = "301001"
joint_type = "R"
/>
19. Open the MotionSolve XML file Pendu_model_usersub.xml from the working directory.
20. Browse through the XML file to locate the Motion_Joint block.
<Motion_Joint
id = "301001"
label = "Motion 0"
type = "USERSUB"
val_type = "D"
usrsub_param_string = "USER(100001,5,2)"
usrsub_dll_name = "NULL"
usrsub_fnc_name = "MOTSUB"
joint_id = "301001"
joint_type = "R"
/>
Note: When the value for the usrsub_dll_name parameter in the above block is set to
NULL, MotionSolve looks for the subroutine in a machine level DLL. This DLL is passed
to MotionSolve by the MS_USERSUBDLL environment variable.
21. To use an element level DLL, set the value of the usrsub_dll_name parameter to point to the DLL.
The usrsub_param_string parameter is used to pass arguments to the user subroutine.
For example, the MOTSUB user subroutine calculates motion using the parameters par1 and par2 in
USER(branch_id, par1, par2) as follows:
motion_val= par1*TIME^par2
MotionSolve uses the value returned from the user subroutine to calculate the motion.
For your convenience, MotionSolve contains a subroutine build tool for Windows and Linux that can
build the subroutine for you. Using this subroutine requires no programming knowledge.
You can also build your user subroutine using an integrated development environment like Microsoft®
Visual Studio® on Windows. This is explained in this tutorial.
Table 1: Minimum Software Requirements to Compile and Build MotionSolve User Subroutine DLLs
Windows Linux
Microsoft Visual Studio version 2005, both Express GCC, version 4.1.2
and Professional
Follow these steps to build a MotionSolve-compatible shared library using available source code.
1. Launch the build tool on Windows by clicking Start > All Programs > HyperWorks (64-bit) >
Tools > MotionSolve Subroutine Builder
The MotionSolve Subroutine Builder dialog is displayed:
Figure 135:
2. To launch the build tool on Linux, navigate to <altair_root>/altair/scripts/ and issue the
command:
./motionsolve_subroutine_builder
Figure 136:
Note: The remainder of this section demonstrates using the build tool on Windows. The
steps for using the tool on Linux are identical.
Important: The source code or object files must all be located in the same directory.
You must have write-to-disk permissions for this directory. If you do not have write-to-
disk permissions for this directory, please copy the source code to a location where you
do have write-to-disk permissions.
Also, if your source/object code is located in different folders on your disk, please copy
all source/object code, along with any relevant files (like headers, for example) to one
common directory. Use this as your working directory in the following steps.
1. To specify the source/object files, click next to the Source File(s) field.
Figure 137:
2. Navigate to your working directory and choose the source files as required. You can choose
multiple files by holding down the CTRL button while clicking the file names, or by clicking and
dragging your mouse pointer.
3. Click Open to select these files.
Figure 138:
Figure 139:
2. Navigate to the directory where you want the shared library to be built. Click Select Folder to
choose the current folder as the output directory.
3. Before building the shared library, you need to specify a name for the shared library. To do this,
simply type in the name (without the extension) into the Output Name field.
Note: The shared library name must contain only alphanumeric characters (A-Z, a-z,
0-9) with the exception of the underscore ("_") character.
Figure 140:
Figure 141:
2. For the Windows platform, if you have multiple compilers installed on your computer, you can
choose which compiler to use while building your shared library.
Figure 142:
Upon building the source files successfully, the following dialog is displayed:
Figure 143:
Additionally, you will see the shared library built by the tool in your working directory (C:\Test in
this case). You can use this library in a MotionSolve simulation.
The tool also creates a temporary directory inside your working directory while building the shared
library. The contents of this temporary directory can be used for debugging and informational
purposes.
Note: The temporary directory created inside of your working directory contains some
useful information:
• build.bat: a batch file that contains the compiler and linker commands used to
build the shared library.
• build_output.log: a log file that contains messages from the compiler and linker.
The contents of this file are useful when debugging an unsuccessful build.
For a successful build, this directory also contains compiled objects, the linked
library and other temporary files. If you specified only C/C++ source files and/or
object files, the tool also creates a Microsoft® Visual Studio® solution file in this
directory.
Figure 144:
3. To investigate the cause of build failure, look at the build_output.log file at the location stated
in the dialog above. This file typically contains compiler/link time errors or warnings that may help
you debug your source code.
4. After you have finished using the tool, you can exit by clicking Quit. If you built a shared library
before quitting, you are given the option to remove the temporary folder created by the tool.
Can the tool build a shared library when both Fortran and C/C++ source code is
specified?
Yes, the tool can handle mixed source code as well as object files.
Where can I get sample templates for the syntax of the C/C++/Fortran code?
Sample user subroutine code is provided in the HyperWorks installation in the following locations:
• For C/C++ source code: <install>\Altair\<version>\hwsolvers\motionsolve\usersub\c_src
• For Fortran source code: <install>\Altair\<version>\hwsolvers\motionsolve\usersub\f_src
Note: For MotionSolve to use the functions defined in the source code, these functions
must be exported on the Windows platform (on Linux, all functions are automatically
exported). The syntax to do this for C/C++ and Fortran is described below.
C/C++
Include the header file msolvsub_c_include.h (located in <install>\Altair
\<version>\hwsolvers\motionsolve\usersub\c_src\include) in your code. To
export a function, use the keywords CLINKAGE, DLLFUNC, and STDCALL.
Fortran
In Fortran syntax, the same function above can be exported as shown below:
SUBROUTINE
ARYSUB (ID, TIME, PAR, NPAR, DFLAG,
& IFLAG, NVALUE, VALUE)
!DEC$ ATTRIBUTES DLLEXPORT ::
ARYSUB
I am not able to compile Fortran files even though I have a supported Intel Fortran
compiler installed. What's wrong?
The build tool relies on an environment variable to detect the version of the Intel Fortran compiler and
its location on your machine. Make sure you have the environment variable IFORT_COMPILERxx (where
xx is the version of the compiler - 10, 11 or 12) defined correctly on your system and pointing to the
installed version.
Note: If you are using a version newer than Visual Studio 2005, you will be prompted
to convert the project file. Please proceed with the default options for the conversion.
Once converted, the new project file is loaded to your workspace.
In the Solution Explorer, the CPP subroutines that are part of the solution are listed.
4. Double-click any of the CPP files that you want to modify/view and make the required changes.
5. Click Save to save the changes made to the file.
6. Choose the configuration for your shared library.
Figure 145:
Make sure that the target type for the shared library matches your HyperWorks installation. For
example, choose x64 for a 64-bit installation of HyperWorks.
7. Select Build > Build Solution to build the DLL. You will be prompted to save the solution. Save
the solution in a directory of your choice.
After successfully completing the build, Visual Studio displays a message as shown below:
Figure 146:
Note: It is assumed that you are familiar with Python and MotionSolve XML syntax.
Using scripting language such as Python gives you power with reduced complexity. These scripts
are interpreted and do not require compiling. Therefore, you do not need a building tool to build
subroutines. Furthermore, scripts are easier to read and understand, and can be used for faster
prototyping.
If you do not have much programming experience, writing scripts for user-subroutines is simpler
than writing C code. For a C user, the usage is even simpler. Besides following the language syntax of
Python, you only need to follow the rules to convert the C code into Python scripts.
For your reference, a sample set of Python user subroutines is available in the hwsolvers\motionsolve
\usersub\py_src folder.
c_datout(&istat);
becomes
istat = py_datout()
In C utility functions, the input and output arguments are combined in an argument list. In
Python, the arguments of the py_* utility functions are strictly the input arguments. All output
arguments should be moved to the left-side as return values of the function call.
2. In C utility functions, any input or output array argument is generally followed by an integer
argument for the array size. In Python utility functions, the integer argument for the array size is
removed because it is not necessary.
ipar[0] = (int)par[0];
ipar[1] = (int)par[1];
c_sysfnc("DM", ipar, 2, &dm, &errflg);
simply becomes
and
ipar[0] = (int)par[1];
ipar[1] = (int)par[0];
becomes
becomes
2. Following the rules specified in last section, the corresponding Python script is shown as:
3. Besides the Python scripts, you also need to specify in the XML model the Python scripts that are
used in the user subroutine. MotionSolve provides this definition through two attributes in the
corresponding elements that uysrsub can be defined.
Figure 147:
5. In the original model, there are six Force_Scalar_TwoBody elements that use SFOSUB written in
C:
<Force_Scalar_TwoBody
id = "30701"
type = "Force"
i_marker_id = "30701010"
j_marker_id = "30701011"
usrsub_param_string =
"USER(50,30301010,30401010,30301010,30401010,10,10,2.0,0.001,0.01)"
usrsub_dll_name = "NULL"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "30801"
type = "Force"
i_marker_id = "30801010"
j_marker_id = "30801011"
usrsub_param_string = "
USER
(50,30301010,30501010,30301010,30501010,10,10,2.0,0.001,0.01)"
usrsub_dll_name = "NULL"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "30901"
type = "Force"
i_marker_id = "30901010"
j_marker_id = "30901011"
usrsub_param_string =
"USER
(50,30301010,30601010,30301010,30601010,10,10,2.0,0.001,0.01)"
usrsub_dll_name = "NULL"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "31001"
type = "Force"
i_marker_id = "31001010"
j_marker_id = "31001011"
usrsub_param_string =
"USER(50,30401010,30501010,30401010,30501010,10,10,2.0,0.001,0.01)"
usrsub_dll_name = "NULL"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "31101"
type = "Force"
i_marker_id = "31101010"
j_marker_id = "31101011"
usrsub_param_string =
"USER(50,30401010,30601010,30401010,30601010,10,10,2.0,0.001,0.01)"
usrsub_dll_name = "NULL"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "31201"
type = "Force"
i_marker_id = "31201010"
j_marker_id = "31201011"
usrsub_param_string =
"USER(50,30501010,30601010,30501010,30601010,10,10,2.0,0.001,0.01)"
usrsub_dll_name = "NULL"
usrsub_fnc_name = "SFOSUB"
/>
6. After changing C SFOSUB into Python SFOSUB, the XML content above is replaced with the
following:
<Force_Scalar_TwoBody
id = "30701"
type = "Force"
i_marker_id = "30701010"
j_marker_id = "30701011"
usrsub_param_string =
"USER(30301010,30401010,30301010,30401010,10,10,2.0,0.001,0.01)"
interpreter = "Python"
script_name = "script/sfosub.py"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "30801"
type = "Force"
i_marker_id = "30801010"
j_marker_id = "30801011"
usrsub_param_string = "USER
(30301010,30501010,30301010,30501010,10,10,2.0,0.001,0.01)"
interpreter = "Python"
script_name = "script/sfosub.py"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "30901"
type = "Force"
i_marker_id = "30901010"
j_marker_id = "30901011"
usrsub_param_string =
"USER(30301010,30601010,30301010,30601010,10,10,2.0,0.001,0.01)"
interpreter = "Python"
script_name = "script/sfosub.py"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "31001"
type = "Force"
i_marker_id = "31001010"
j_marker_id = "31001011"
usrsub_param_string =
"USER(30401010,30501010,30401010,30501010,10,10,2.0,0.001,0.01)"
interpreter = "Python"
script_name = "script/sfosub.py"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "31101"
type = "Force"
i_marker_id = "31101010"
j_marker_id = "31101011"
usrsub_param_string =
"USER(30401010,30601010,30401010,30601010,10,10,2.0,0.001,0.01)"
interpreter = "Python"
script_name = "script/sfosub.py"
usrsub_fnc_name = "SFOSUB"
/>
<Force_Scalar_TwoBody
id = "31201"
type = "Force"
i_marker_id = "31201010"
j_marker_id = "31201011"
usrsub_param_string =
"USER(30501010,30601010,30501010,30601010,10,10,2.0,0.001,0.01)"
interpreter = "Python"
script_name = "script/sfosub.py"
usrsub_fnc_name = "SFOSUB"
/>
7. With these changes (C code into Python code and XML model change), the model with Python user
subroutines are ready to run with MotionSolve.
• MV-7000: Modeling Differential Equations Using MotionView and MotionSolve (p. 180)
• MV-7002: Co-simulation with Simulink (p. 187)
• MV-7003: Simulating a Single Input Single Output (SISO) Control System Using MotionView and
MotionSolve (p. 199)
• MV-7004: Inverted Pendulum Control Using MotionSolve and MATLAB (p. 203)
• MV-7005: Linking Matlab/Simulink Generated Code (Simulink Coder) with MotionSolve (p. 210)
• MV-7008: Co-simulation with AcuSolve (p. 220)
• MV-7009: Remote Co-simulation with Simulink (p. 237)
• MV-7010: Co-Simulation with Activate - Quadrotor Control (p. 252)
MotionSolve Tutorials
Advanced Simulation p.180
Differential equations are very versatile and have many different applications in modeling multibody
systems. User-defined dynamic states are commonly used to create low pass filters, apply time lags to
signals, model simple feedback loops, and integrate signals. The signal may be used to:
• define forces.
• used as independent variables for interpolating through splines or curves.
• used as input signals for generic control modeling elements.
• define program output signals.
The MotionSolve expressions and user-subroutines allow you to define fairly complex user-defined
dynamic states.
The expression type is used when the algorithm defining the differential equation is simple enough to
be expressed as a simple formula. In many situations, the dynamic state is governed by substantial
logic and data manipulation. In such cases, it is preferable to use a programming language to define the
value of a differential equation. The user-defined subroutine, DIFSUB, allows you to accomplish this.
(6)
(7)
(8)
Two types of solver variables are available. The first, and probably the most convenient, is the
expression valued variable. The second is the user-subroutine valued variable.
The expression method is used when the algorithm defining the algebraic state is simple. In many
situations, the algebraic state is governed by substantial logic and data manipulation. In those cases, it
is preferable to use a programming language to define the value of a solver variable. The user-defined
subroutine, VARSUB, enables you to do this.
Solver variables are quite versatile and have many different applications in modeling multibody
systems. They are commonly used to create signals of interest in the simulation. The signal may then
be used to define forces, independent variables for interpolation, inputs to generic control elements,
and output signals.
MotionSolve expressions and user-subroutines allow for fairly complex algebraic states to be defined.
For more information, please refer to the MotionView and MotionSolve User's Guides in the online help.
Figure 148:
6. From the Properties tab, under Type, select Linear and enter a value of 1.4 in the field.
Figure 149:
(9)
Differential Equation (or right-click Solver Differential Equation, from the toolbar.
This is an implicit differential equation that has a constant ( ). The initial condition of the differential
equation (IC) and its first derivative (IC dot) are known (given).
6. Select SolverDiff 0.
7. From the Properties tab, select Implicit and specify IC and IC dot as 2000 and -58875,
respectively.
Figure 150:
Figure 151:
`-DIF1 ({diff_0.id})/DIF({diff_0.id})+{sv_3.value.lin}*DIF1({diff_1.id})/
DIF({diff_1.id})`
11. Optional: You can use the model tree to access entity variables in your model. As you can see for
the above expression, to refer to the ID of the differential equation, browse for it from the list-tree
on the Properties tab and select the ID. Click Apply.
The name of the selected entity or property is inserted into the expression.
12. Click OK.
The new expression is displayed in the text box on the panel.
13. Repeat steps 6 through 12 to modify the remaining two differential equations:
Implicit: Yes
IC: 560
IC_dot: -4710
Value Expression:
`DIF1({diff_0.id})/DIF({diff_0.id})-DIF1({diff_1.id})/DIF({diff_1.id})-
DIF1({diff_2.id})/DIF({diff_2.id})`
Implicit: No
IC: 0.000256
Value Expression:
`-{sv_1.value.lin} *sqrt(abs({sv_0.value.lin}*DIF({diff_2.id})*DIF({diff_0.id}) /
{sv_2.value.lin}))*0.5787`
Figure 152:
3. From the Main tab, choose Save and run current model.
4. Click on the browser icon and specify a filename of your choice.
5. Click Save.
6. Click Check Model to check the model.
In IPC co-simulation, the two solvers are run on two separate processes with data being exchanged
through sockets.
Note: Older versions of MATLAB/Simulink may work, but the above minimum versions are
recommended and tested
Hardware requirements:
• PC with 64-bit CPU, running Windows 7/10 or higher
• Linux RHEL 6.6 or CentOS 7.2
Both the pendulum and the cart are modeled as rigid bodies. The controller, modeled in Simulink,
provides a control force to the cart to stabilize the inverted pendulum and prevent it from falling. This
control force is applied to the cart via a translational force. The model setup is illustrated in the figure
below.
The pre-designed controller generates a control force that keeps the pendulum upright. The controller
uses the pendulum's orientation and angular velocity along with the cart's displacement and velocity as
inputs to calculate the direction and magnitude of the force needed to keep the pendulum upright. A
block diagram of the control system is shown below.
A disturbance is added to the computed control force to assess the system response. The controller
force acts on the cart body to control the displacement and velocity profiles of the cart mass.
, where
is the error (difference between reference and actual values) on the input signals.
The angular displacement and velocity of the pendulum are obtained by using the AY() and WY()
expressions respectively. The translational displacement and velocity of the cart are obtained similarly,
by using the DX() and VX() expressions.
1. From the Start menu, select All Programs > HyperWorks <version> MotionView. Open the
model InvertedPendulum_NoCosimulation.mdl from your <working directory>.
Slider Trans Joint Translational joint Translational joint between the cart body
and the ground
Pendulum Rev Joint Revolute joint Revolute joint between the pendulum body
and the cart body
Control Force Vector force The control force applied to the cart body
Output control force Output request Use this request to plot the control force
Output slider Output request Use this request to plot the cart's
displacement displacement
Output slider velocity Output request Use this request to plot the cart's velocity
Output pendulum Output request Use this request to plot the pendulum's
displacement displacement
Output pendulum Output request Use this request to plot the pendulum's
velocity velocity
Pendulum Angular Solver variable This variable stores the rotational velocity
Velocity of the pendulum via the expressionVY()
2. In the Run panel, specify the name InvertedPendulum_NoCosimulation.xml for the MotionSolve
model name and click Run.
The results achieved will be used as the baseline to compare the results obtained from co-
simulation.
Control_PlantOutput model elements and provide these connections. In this tutorial, this has already
been done for you, and you can see this by opening the model InvertedPendulum_Cosimulation.mdl
from your <working directory>.
This model contains two additional modeling components:
The Control_PlantInput element defines the inputs to a mechanical system or plant. For this model, only
one input is defined in the "Plant Input Simulink" solver array. This is set to the ID of the solver variable
that holds the control force from Simulink.
The Control_PlantOutput element defines the outputs from a mechanical system or plant. For this
model, four outputs are defined in the "Plant Output Simulink" solver array. These are the pendulum
rotation angle, the pendulum angular velocity, slider displacement and slider velocity.
The inputs specified using the Control_PlantInput and Control_PlantOutput elements can be
accessed using the PINVAL() and POUVAL() functions, respectively. Since the Control_PlantInput and
Control_PlantOutput list the IDs of solver variables, these input and output variables may also be
accessed using the VARVAL() function. For more details, please refer to the MotionSolve User's Guide.
Environment
Value Windows shell Linux shell MATLAB shell
variable
LD_LIBRARY_PATH - <altair>\hwsolvers\motionsolve
\bin\linux64
<altair>\hwsolvers\common\bin
\linux64:$LD_LIBRARY_PATH
where <altair> is the full path to the HyperWorks installation. For example, on Windows, this
would typically be C:\Program Files\Altair\<version>.
2. Note that other optional environment variables may be set for your model. See MotionSolve
Environment Variables for more information on these environment variables.
The S-Function library for co-simulation with MotionSolve is called mscosimipc – for Inter Process
Communication (IPC) using TCP/IP sockets for communication. This file is installed under <altair>
\hwsolvers\motionsolve\bin\<platform>.
The location of this file needs to be added to the search path of MATLAB for the S-Function to use
mscosimipc.
b) From the dialog, add the directory where the mscosimipc library resides.
<altair>\hwsolvers\motionsolve\bin\win64
c) Select Save and Close.
This procedure permanently adds this directory to the MATLAB/Simulink search path.
2. Use MATLAB commands.
a) To add the directory where mscosimipc library resides into the MATLAB search path, at the
MATLAB command line, type
addpath('<altair>\hwsolvers\motionsolve\bin\<platform>')
Note: You can also create a .m script to make this process more easily
repeatable.
For example, you can set the MATLAB Path and the necessary environment
variables using MATLAB commands in a MATLAB (.m) script:
addpath('<altair>\hwsolvers\motionsolve\bin\win64')
setenv('NUSOL_DLL_DIR','<altair>\hwsolvers\motionsolve\bin\win64')
setenv('RADFLEX_PATH',['<altair>\hwsolvers\common\bin\win64')
setenv('PATH',['<altair >\hwsolvers\common\bin\win64;'
getenv('PATH')])
setenv('LD_LIBRARY_PATH', '<altair>\hwsolvers\motionsolve\bin
\linux64:<altair>\hwsolvers\common\bin\linux64\')
4. The model contains an S-function block. Name the S-function 'mscosim'. Double click on the S-
Function named mscosim. In the dialog box that is displayed, change the name of the S-function
to ‘mscosimipc’.
The S-function (system-function) is one of the blocks provided by Simulink and represents the
MotionSolve model. It can be found in the Simulink User-Defined Functions block library. An S-
Function allows you to model any general system of equations with inputs, outputs, states, and so
on, and is somewhat analogous to a Control_StateEqn in MotionSolve. See the MATLAB/Simulink
documentation for more details.
5. Double-click the S-function with name mscosimipc. In the dialog that is displayed, under the S
Function Parameters, enter the following using single quotes:
Figure 160:
3. Click the file browser and load the InvertedPendulum_NoCosimulation.mrf file. This was the
baseline result created by running MotionSolve by itself.
4. In the Page Controls toolbar, create two vertical plot windows.
5. Select Marker Displacement for Y-Type, REQ/70000004 Output slider displacement (on
Slider cart) for Y Request, and DX for Y Component to plot the cart's translational displacement:
8. Click the file browser icon and load the InvertedPendulum_Cosimulation.mrf file. This was the
co-simulation results run with Simulink.
9. Select Marker Displacement for Y-Type, REQ/70000004 Output slider displacement (on
Slider cart) for Y Request, and DX for Y Component to overlay the plot in the left window.
10. Select Marker Force for Y-Type, REQ/70000002 Output control force- (on Slider cart) for Y
Request, and FX for Y Component to overlay the plot in the right window.
Both the signals match as shown below.
Figure 164: Comparison of the Cart Displacement and Cart Control Force Between the Two Models
The blue curves represent results from the MotionSolve-only model and the red curves represent
results from the co-simulation.
Consider the problem of maintaining the reference speed of a rotor in the presence of disturbances. A
block diagram of the control system is shown in the figure below.
One simple approach is to design a proportional integral (PI) controller (Ogata, 1995), such that:
(10)
1. From the Project Browser, right-click Model and select Add General MDL Entity > Solver
Variable (or right-click from the toolbar.
The Add SolverVariable dialog will be displayed.
2. Change Label to Reference Speed.
The variable name remains sv_0.
3. Click OK.
4. To maintain a linear speed of 3 rad/sec, from the Type drop-down menu, select Linear and enter
3 as the value of the solver variable.
'-WZ({MODEL.b_0.cm.idstring})+{sv_0.value}'
Note the single back quotes, indicating the expression is not to be processed by MDL, but by
Templex. The parameters inside the curly braces are evaluated.
4. Click the Properties tab.
5. To add Numerator coefficients, click Append.
6. Enter 10 and 1 for the coefficients of 1 and s, respectively.
7. Similarly, for Denominator coefficients, click Append and enter 0 and 1 for the coefficients of 1
and s, respectively.
1. From the Project Browser, right-click Model and select Add Force Entity > Force (or right-click
Forces ).
The Add Force or ForcePair dialog is displayed.
2. Leave the label and variable name default settings and click OK.
3. From the Connectivity tab, under Force, select Action Reaction. For Properties, select
Rotational.
4. Set Local ref. frame by double-clicking Ref Marker and selecting Global Frame.
5. Double-click Body 1 for Action force on: and select the rotor body.
6. Double-click Body 2 for Reaction force on: and select Ground Body.
7. Double-click Point 1 for Apply force at: and select Point 0.
8. Click the Rot Properties tab and leave Tx and Ty set to 0.
9. Under Tz, select Expression and enter '{MODEL.siso_0.OUTPUT}'.
Tip: You may also click to access the expression builder and create this expression
using the model tree.
2. Under Simulation type, select Transient and specify the output (.xml) filename.
3. Enter 25 for the End time.
4. Click Run.
Reference
K. Ogata, Modern Control Engineering, 1990, Prentice-Hall Inc., Englewood Cliffs, N.J., US
The goal of this tutorial is to design a regulator using the pole placement method. The inverted
pendulum MDL model file is supplied.
The image below shows the classic inverted pendulum on a slider. The system has two degrees of
freedom leading to four state variables. The vertically upright position of the pendulum is unstable. The
goal is to design a regulator to stabilize this configuration.
You want to find a full-state feedback control law to achieve the goal. The control input is a force
applied to the slider along the global X-axis. Plant output is the pendulum angle of rotation about the
global Y-axis.
Start by loading the file inv_pendu.mdl, located in the mbd_modeling\motionsolve folder, into
MotionView. Upon examination of the model topology, you will notice that everything needed for this
exercise is already included in the model. However, depending on which task you are performing, you
will need to activate or deactivate certain entities.
1. From the Project Browser, click Forces and make sure that Control ForceOL is activated, while
Control Force - CL and Disturbance-step are deactivated.
2. From General Actions toolbar, click Run .
1 -1.625311E-02 0.00000000E+00
2 -4.003403E-01 0.00000000E+00
3 5.582627E-01 0.00000000E+00
4 -1.733216E+00 0.00000000E+00
There is one eigenvalue with a positive real part, indicating that the system is unstable in the
current configuration.
8. Click Animate.
The result animation H3D will be loaded in the adjacent window.
9. From the Results Browser select individual modes.
Figure 169:
where , , , and are the state matrices, is the state vector, is the input vector, and is the
output vector. The A,B,C,and D matrices depend on the choice of states, inputs, and outputs. The states
are chosen automatically by MotionSolve and the chosen states are reported in one of the output files.
You only need to define the inputs and outputs.
1. Expand the Solver Variables folder in the Project Browser and examine the entities.
• Control Force Variable - CL is used to define the control input after the control law has been
found. Ignore this at this stage.
• Control Force Variable - OL is used to define the control plant input, which is a force named
Control Force - OL. This force is applied to the slider body. This variable is set to zero. It is
needed by MotionSolve to properly generate the linearized system matrices.
• Solver variable Pendulum Rotation Angle defines the control plant output and measures the
pendulum rotation about the Global Y-axis.
2. Expand the Solver Array folder in the Project Browser and examine the solver arrays that are
defined.
a) Select Plant-I. This array defines a solver array entity of type Plant-Input.
b) Ensure that Solver Variable is set to Control Force Variable - OL and click OK.
c) Select Plant-O. This array defines a solver array entity of type Plant-Output.
d) Ensure that Solver Variable is set to Pendulum Rotation Angle.
Note: Please note that the plant input and plant output IDs used in linearization
are specified automatically by MotionView while exporting the solver deck.
3. Click Run .
4. From the Simulation type drop-down menu, select Linear.
Figure 170: Linear Tab in Simulation Settings Dialog for Specifying the MATLAB Matrix Files Output
6. From the Simulation Settings dialog, Linear tab select the State-Space matrices (MATLAB)
option.
7. From the Main tab, click Run.
You should get six new files with base name inv_pendu_state_matrices and extensions .a,
.b, .c, .d, .pi, and .po. The .pi and .po files contain information about the input and output
variables.
The states chosen by the MotionSolve solver are:
• Angular displacement about the global-Y axis.
• Translation displacement along the global X-axis.
• Angular velocity about the global-Y axis.
• Translation velocity along the global X-axis of the pendulum body center of mass marker.
It can be easily verified using MATLAB that the system is completely state controllable [1, 2]. We
employ a full-state feedback control law , where is the control input, is the gain vector,
and is the state vector. Then, assuming the desired pole locations are stored in vector , you may
use the pole placement method to compute . For desired poles at [-20 -20 -20 -20] (rad/s), the acker
function in MATLAB yields k=1e3[-2.4186 -0.0163 -0.070 -0.0033].
`-1e3*(-2.4186*AY({b_pendu.cm.idstring})-0.0163*DX({b_pendu.cm.idstring}),-0.070*WY({b_pendu.cm.idstring})-0.0033*VX({b_pendu.cm.idstri
Notice that it is simply the dot product between the gain vector (k) and the state vector (x) elements.
This solver variable is used to define a force named Control Force - CL.
1 -1.9595991E+00
2 -4.6976071E+00
They all have negative real parts, hence the system is stabilized. Note that the negative real parts
are close to the desired poles (-20 rad/s = -3.038 Hz).
2. To run a dynamic simulation with MotionSolve, from the Project Browser, activate deactivated
outputs Output control force - final and Output Disturbance step.
3. From the toolbar, click Run .
The plots of disturbance force, control force, slider x displacement, and pendulum angular
displacement are shown below.
Figure 171: Plots of Disturbance and Control Forces as well as Slider Translational and Pendulum Angular
Displacements
References
Feedback Control of Dynamic Systems, G. G. Franklin, J. D. Powell, and A. Emami-Naeini, Third Edition,
Addison Wesley.
Check for supported versions of MATLAB and MSVS at Supported Versions - Third Party Software in the
XML Format Reference Guide.
<Control_PlantInput
id = "30100100"
num_element = "2"
variable_id_list = "30100400, 30100500"
sampling_period = "0.01"
offset_time = "0.0"
label = "for controller 1"
usrsub_param_string = "USER(987654321)"
usrsub_dll_name = "rtw_BusSuspension2PMIMODiscrete"
usrsub_fnc_name = "PINSUB"
hold_order = "2"
/>
<Control_PlantOutput
id = "30100200"
num_element = "2"
variable_id_list = "30100200, 30100300"
sampling_period = "0.01"
offset_time = "0.0"
label = "for controller 1"
usrsub_param_string = "USER(987654321)"
usrsub_dll_name = "rtw_BusSuspension2PMIMODiscrete"
usrsub_fnc_name = "POUTSUB"
hold_order = "2"
/>
<Control_PlantInput
id = "30100300"
num_element = "2"
variable_id_list = "30100800, 30100900"
sampling_period = "0.01"
offset_time = "0.0"
label = "for controller 2"
usrsub_param_string = "USER(987654321)"
usrsub_dll_name = "rtw_BusSuspension2PMIMODiscrete"
usrsub_fnc_name = "PINSUB"
hold_order = "2"
/>
<Control_PlantOutput
id = "30100400"
num_element = "2"
variable_id_list = "30100600, 30100700"
sampling_period = "0.01"
offset_time = "0.0"
label = "for controller 2"
usrsub_param_string = "USER(987654321)"
usrsub_dll_name = "rtw_BusSuspension2PMIMODiscrete"
usrsub_fnc_name = "POUTSUB"
hold_order = "2"
/>
The key attributes of Control_PlantInput and Control_PlantOutput needed to link a Simulink Coder
DLL are listed below.
Attribute Description
usrsub_dll_name The name of the DLL that is used (for example, from Simulink
Coder).
In this case, this MotionSolve model has been prepared for you. Copy the MotionSolve and Simulink
models, rtw_BusSuspension2PMIMODiscrete.xml and rtw_BusSuspension2PMIMODiscrete.mdl,
located in the motionsolve\cosimulation folder to your <working directory>.
Figure 172:
Note: If you have multiple inports/outports, you must retain the above illustrated naming
scheme. All your inports must be defined as In1, In2, ..., Inx. Similarly, all your outports
must be named as Out1, Out2, ..., Outx. This is a limitation within the current co-simulation
framework and will be addressed in a future release. See Appendix B for more information.
The order of these Inport's and Outport's must match the order of the Control_PlantOutput's and
Control_PlantInput's, respectively, in the MotionSolve model.
Figure 173:
Figure 174:
4. Change the System target file by clicking Browse and searching for "grt.tlc - Create Visual C/C
++ Solution File for the "grt" target". This is shown below:
Figure 175:
5. Once this is done, change the Language option to "C++" in this same Code Generation window.
6. Next, in the left-side browser/tree, select the Solver option.
Simulink Coder does not allow using a variable-step integrator for the Generic Real-Time target
that is required by MotionSolve to generate this code (more details on selecting the Generic Real-
Time target later in this tutorial). So, under the Solver option on the left, choose the Fixed-step
solver, as shown below:
Figure 176:
Note: See the Mathworks documentation for more details on selecting an appropriate
fixed-step size for your model (in particular, if the model has multiple sample times,
you will likely need to choose a step size equal to the least common denominator of
the specified sample times so that each sample time is hit by the solver).
7. Next, in the left-side browser/tree, select the Code Generation option again.
8. Click Build to build the code.
The code generation creates two folders in the current directory of MATLAB (here
<Simulink_model> is the name of the model):
• <Simulink_model>_grt_rtw
• slprj
You should see messages that look similar to those below and end with: ###
Successful completion of Real-Time Workshop build procedure for model:
rtw_BusSuspension2PMIMODiscrete
… or something similar.
Figure 177:
1. Open a command prompt in your working directory (where Simulink has generated the code).
2. Issue the following command:
where,
<mdl_name> is the name of the Simulink model (without the extension .mdl)
<altair_root> is the complete path to the root folder of the HyperWorks installation
<msvs_root> is the complete path to the root folder of the MSVS installation
<win32|win64> specify win32 or win64 depending on the required platform of the DLL
3. To successfully issue the ms_rtw_pre command, please include the path of the MotionSolve
binaries in the "PATH" environment variable. This can be done locally by issuing the following
command on Windows:
where <MS_bin_path> is the path to the MotionSolve binaries; for example, "C:\Program Files
\Altair\<version>\hwsolvers\motionsolve\bin\win64"
4. If the path to <altair_root> and/or <msvs_root> contains spaces, make sure to enclose the path
in quotes.
ms_rtw_pre
rtw_BusSuspension2PMIMODiscrete "C:\Program Files\Altair\<version>" "C:\Program Files
(x86)\Microsoft Visual Studio 10.0" "win64"
You can confirm that this process has completed successfully by looking at the output in the command
window. On successful execution, you should see something like the following:
1. In this example, the ms_pre_rtw script should have created the generated DLL into the same
folder where the MotionSolve model (.xml) resides. If the DLL is created elsewhere, copy it to the
working directory of the MotionSolve .xml file.
2. Open a command window and change the path into this folder in order to run the model.
3. You will be running the MotionSolve model on command line, so certain environment variables
must be set to be able to invoke MotionSolve. See the MotionSolve User's Guide for more details
on the options to run on the command line.
4. Run the MotionSolve model in the command line by issuing the command "mbd_d x.xml x.mrf".
The simulation should run quickly and you should review your results to confirm that the process
worked as expected.
Appendix A
This method updates the input data structure in the Simulink Coder generated code with the output
from MotionSolve.
The first argument requests a pointer to the API ID. The API ID is passed from the model XML in the
line usrsub_param_string = "USER(987654320)". The first parameter in the USER() string is always
the ID of the API. The MotionSolve API provides the method void * CoSimAPI_Get_API_Ptr(int
api_id) to get the API pointer, where the api_id is the number specified in the XML file in the USER()
string.
The second argument requests data structure x_M related to the generated Simulink Coder model
information where 'x' is the name of the model. The x_M data structure is inherent to the Simulink
code.
The last argument requests input x_U where x_U is the data structure used by the Simulink Coder code
to store the external inputs (see Appendix B).
This method updates the input for the MotionSolve solver with output from the RTW generated code.
The first and second arguments are the same as described in the previous section.
The last argument requests RTW output x_Y which is deposited to MotionSolve for that current time
step, where x_Y is the data structure used by the Simulink Coder code to store the external outputs
(see Appendix B).
Appendix B
This section describes the data structure that Simulink Coder generated code uses for representing the
external input/output ports. In the following lines, the name of the model is assumed to be rtw_MS (rtw
= Real Time Workshop, former name of Simulink Coder).
Typically, the Simulink Coder generated code (SCGC) uses the following notations:
Output port from Simulink with single channel rtw_MS_Y.Out1, rtw_MS_Y.Out2 etc.
So for example, for a model with two Control_PlantInput (CPI) elements where the first has three
channels and the second has two channels, the corresponding data structure in Simulink Coder code
would be:
The same scheme is applicable for the data structure that handles Control_PlantOutput ports.
Note: If the Simulink model has labels defined for the input/output links, then these labels
will replace "In" and "Out" in the data structure described above. "In" and "Out" are the
default names used by Simulink in case the links are not named. In this scenario, you
need to change the first input variable name specified in the rtw api function template
CoSimAPI_SimulinkRTW_Update_U(api,model,input) into the one you specified.
For example, if you name the first input to be myIn instead of In1, you need to make the following
change to that function template:
In this scenario, MotionSolve computes the displacements and rotations for the rigid bodies, while
AcuSolve computes the forces and moments on those bodies. Both solvers exchange data with each
other while stepping forward in time via the TCP socket protocol. This means that the two solvers can
be located on different machines and on different platforms and still communicate with one another. For
example, the CFD simulation can run on an HPC, while the MBS simulation can run locally on a laptop.
Tutorial Objectives
You will use the MotionSolve-AcuSolve co-simulation interface to couple the rigid body dynamics of
a check valve within a pipe with the flow field. The AcuSolve model has already been setup for you
and is located at <installation_directory>\tutorials\mv_hv_hg\mbd_modeling\motionsolve
\cosimulation\Check_Valve_Coupled.acs. Steps for running this model in AcuSolve are included as
part of this tutorial.
To learn more about how to setup the model in AcuSolve, please refer to <installation_directory>
\acusolve\<platform>\help\acu\acusolve_tut\Tutorials\Check_Valve_Coupled\.
Software Requirements
To successfully complete this tutorial, the following must be installed:
Machine A Machine B
From the table above, the co-simulation is currently only supported for the Windows 64-bit platform
for MotionView and MotionSolve. You may use either a Windows 64-bit or a Linux 64-bit installation of
AcuSolve.
Simulation Environment
The co-simulation interface between MotionSolve and AcuSolve consists of a “middleware” utility
executable, acuMSI.exe. This executable is responsible for:
The geometry that is modeled in this tutorial is illustrated in the figure below. It consists of:
• A pipe with an inlet and outlet for the fluid flow.
• A check valve assembly that consists of a shutter plate attached to a stem.
• A stop mounted on a perforated plate downstream of the shutter body.
• The fluid flow in the pipe is assumed to be axisymmetric. This allows you to model only a part of
the check valve. In this example, a 30 degree section of the geometry is modeled, as shown by the
blue part in the figure below. The advantage of doing this is a reduced simulation time while still
capturing an accurate solution.
The check valve assembly consists of a disc-like body mounted on a stem. When fluid flows in the
direction specified by the red arrows in the figure above, the fluid forces the shutter body to translate
in the same direction as the fluid. The motion of the shutter body is also affected by a spring damper
attached between the shutter body and the perforated plate. Finally, 3D rigid body contact is modeled
between the shutter body and the stop to arrest the motion of the shutter body in the direction of the
flow.
For the MBS model, only 1/12 of the shutter body and the perforated plate are modeled.
At the start of the simulation, the flow field is stationary. A pressure specified at the inlet drives the
flow, which varies over time as a piecewise linear function. This is illustrated in the figure below. As this
pressure rises, the flow accelerates which in turn pushes the shutter body open and allows flow through
the pipe.
This dynamics of this kind of model can be termed as being “tightly” coupled between the two solvers.
This means that the motion of the rigid bodies affects the fluid flow field, which in turn affects the rigid
body motion in a cyclical fashion.
The rest of this tutorial assumes that this model has been correctly setup in AcuSolve. Note that
the model is designed to translate the shutter body until it collides with the perforated plate. The
MotionView model has been designed with a contact between these two bodies that causes the shutter
body to rebound appropriately. To allow the rigid bodies to come into contact without the AcuSolve finite
element mesh fully collapsing, the perforated plate in the fluid model has been offset by 0.002m in the
positive X direction. This allows the MotionView model to react as specified by the contact entity while
keeping the AcuSolve mesh from fully collapsing.
To specify a body as "wet" in MotionView, you have to make use of a system definition, which is
described below.
1. Add the system definition to your model by locating the Model system in your Project Browser and
select it.
This changes the panel selection at the bottom.
2. From the Import/Export tab, select Import and click the File open icon, .
3. The system definition that is used for this co-simulation is located at <installation_directory>
\utility\mbd\fluid_force\sys_fluid_force.mdl. Click Import to import the file.
The Import Definition dialog is displayed.
4. Leave the labels as-is and click OK.
Figure 183: Defining the rigid body associated with the “wet” body
Shutter Body - AcuSolveForce Action Only, TransRotational The force and moment
Force calculated by AcuSolve is
applied to the “wet” body
through this force component.
FromAS_TX
FromAS_TY
At this point, you have setup the model in MotionView to interact with AcuSolve.
1. To deactivate the template Define co-simulation with AcuSolve shown in the figure below,
right-click on it in the browser and select Deactivate.
By doing this, you are deactivating the flag which tells MotionSolve that this model is intended
for co-simulation with AcuSolve. Thus, MotionSolve simulates this model as a stand-alone model
without co-simulating with AcuSolve
You may run this model using the Run panel in MotionView and ensure that there are no error or
warning messages reported. This is recommended to ensure that the model works properly before
attempting a co-simulation.
If you load the animation H3D generated from running this model, you will see that there is
no motion in any of the parts. This is because all of the actuation for this model comes from
AcuSolve, which was disabled for this simulation.
2. After you have verified the model, re-activate the template Define co-simulation with
AcuSolve to perform a co-simulation, as shown in the figure below:
1. The name of the “wet” body/bodies need to match between MotionSolve and AcuSolve. The
names of the “wet” body/bodies are specified in the *.inp file on the AcuSolve side.
Note: The names are case-sensitive and must match exactly (see the text in red
below).
MotionSolve (.xml):
AcuSolve (.inp):
2. The print_interval for the MotionSolve model needs to match the step size for the AcuSolve model.
For this tutorial, it is set to 0.002s.
3. You must set the MotionSolve step size, h_max, to match the print_interval (0.002s in this case).
4. Also, verify that the end times for both models are set to the same values. For this tutorial, the
end times for both the AcuSolve and MotionSolve models are set to 0.35s.
See the Run Panel in MotionView to set the print_interval, step size (h_max), and end times.
Note that the units in the MotionSolve and AcuSolve models do not need to match to run the co-
simulation; however, the units must match to overlay the results animations in HyperView. The
units in MotionView are set via the Units form shown below:
All values in the MotionSolve model are set with respect to these units settings.
2. Click the ellipsis button next to the Options field to open the Available Options dialog.
3. Activate the –as_cosim option. When this flag is enabled, it tells the Run Manager to do the
following:
a) Invoke the MotionSolve executable and run the model that is specified.
b) Invoke the middleware “acuMSI”, which enables communication between MotionSolve and
AcuSolve.
When you activate this option, the following dialog is displayed and you are prompted for
additional options:
acuMSI Options
argument, you also have to specify the changed port number
in the AcuSolve input file.
-mi <integer> Specifies the maximum number of iterations per time step
between the two solvers. The default is 0.
-v <integer> Specifies the verbosity level of the output file from acuMSI.
The default is set to 0 (verbosity OFF).
6. You are now setup to start the co-simulation on the MotionSolve side. Click Run.
This launches MotionSolve as well as the acuMSI executable. The MotionSolve run is paused at the
first time step – it is now in waiting mode and the co-simulation will start as soon as AcuSolve is
run.
For this model, the default values are used. AcuSolve runs using a single processor, and
AcuConsole generates the input files and launches AcuSolve.
3. Press Launch to launch the solution process.
As the solution starts, an AcuTail window opens. After executing AcuPrep, AcuSolve stops at the
acuRun path step. It’s waiting for the execution of the process.MotionSolve
Soon, AcuSolve and MotionSolve should begin to communicate with one another. You should
be able to see relevant time stepping information in both solver windows. For example, you
should see something like the following in the MotionSolve window at the beginning of the co-
simulation:INFO: [AS-COSIM] Connected to AcuMsi on port 94043 INFO: [AS-COSIM] License
checked out. … Time=2.000E-06; Order=1; H=2.000E-06 [Max Phi=1.314E-16] Time=3.600E-02;
Order=2; H=2.000E-03 [Max Phi=1.653E-08] …
The co-simulation should take roughly 15 minutes to complete on a laptop (Intel i7. 2.8GHz).
Note that there is no order dependency on launching the co-simulation – either MotionSolve or v
can be launched first.
The animation H3D generated by the MotionSolve part of the co-simulation contains only the results
from MotionSolve. Similarly, the result files from AcuSolve only contain the results for the AcuSolve
model. To animate the results from the co-simulation, follow these steps:
1. Load the animation H3D generated by MotionSolve in HyperView.
a) Go to the Load Model panel.
b) Click the file open button, , next to Load model and navigate to the results directory (the
same directory where the .xml file is located).
2. HyperView loads the MotionSolve results file into the graphical window at the first time step. From
this point, you can animate the transient results using Start/Stop on the Animation Slider.
3. To load the AcuSolve results, they must first be converted to the .h3d format. This can be
accomplished by using the AcuSolve utility, AcuTrans. AcuTrans is available from the Start menu.
Select All Programs >HyperWorks <version> (64-bit) > AcuSolve > AcuSolve Cmd Prompt.
4. Navigate to the results directory and execute the following command to convert the AcuSolve
database into the .h3d format:
This creates a single .h3d file containing all of the time steps available for the simulation.
5. Using AcuTrans, overlay the newly-created H3D over the MotionSolve result H3D in HyperView.
This is accomplished by repeating Step 1 described above and activating Overlay when selecting
the AcuSolve result H3D.
Figure 196: Overlaying AcuSolve H3D over the MotionSolve H3D in HyperView
Once loaded, the graphical window contains both results and can be animated as before. To
visualize the information contained within the AcuSolve results, a Contour plot may be used. Click
on the Contour button to display the panel.
6. Set the options as shown in the figure below and click Apply.
Figure 197: Overlaying AcuSolve H3D over the MotionSolve H3D in HyperView
This creates a contour plot of the velocity magnitude overlaid with the results from MotionSolve in
one window.
Figure 198: Velocity magnitude plot overlaid with the MotionSolve results in HyperView
This automatically adjusts the graphical window to accommodate two pages, defaulting to two
instances of HyperView.
9. Click anywhere in the page on the right and switch to HyperGraph by clicking the Page Selector
button and selecting HyperGraph 2D from the drop-down list.
10. Click the Build Plots button to load the .plt file from the same results directory.
Once the .plt file is loaded into HyperGraph, the two outputs are available for plotting.
11. Perform the following selections:
a) Under Y Type, select Displacement.
b) Under Y Request, select Displacement (on Shutter Body).
c) Under Y Component, select X.
d) Click Apply.
HyperGraph can be used to create additional traces on the same plot to generate the following
plots.
Figure 201:
MotionSolve allows you to co-simulate with Simulink when the two software are remotely located,
through an implementation of the Inter Process Communication (IPC) approach via sockets.
Note: Older versions of MATLAB/Simulink may work, but the above minimum versions are
recommended and tested.
Hardware requirements:
• PC with 64bit CPU, running Windows 7/10 and/or
• Linux RHEL 6.6 or CentOS 7.2 64
Simulation Environment
In this tutorial, it is assumed that MATLAB is installed on Machine "A" and MotionSolve is installed on
Machine "B". The following scenarios are feasible:
Note: When you start the co-simulation from Simulink, a few MotionSolve binaries are
loaded by Simulink at runtime. For this purpose, a reduced installation of MotionSolve
is needed on the machine where Simulink resides. Also, this installation of MotionSolve
must be of the same platform type as Simulink. For example, to do an IPC co-simulation
between Simulink on Linux and MotionSolve on Windows, you would need to have certain
MotionSolve Linux binaries on the same machine where the Simulink software is installed.
These libraries are listed in the appendix. The table above is updated below to reflect this.
This tutorial describes the process to perform a co-simulation between a 64-bit installation of Simulink
on Machine "A" and a 64-bit installation of MotionSolve on Machine "B" (the scenario that is in blue text
in the table above). This is illustrated better in the figure below.
Both the pendulum and the cart are modeled as rigid bodies. The controller, modeled in Simulink,
provides a control force to the cart to stabilize the inverted pendulum and prevent it from falling. This
control force is applied to the cart via a translational force. The model setup is illustrated in the figure
below.
The pre-designed controller generates a control force that keeps the pendulum upright. The controller
uses the pendulum's orientation and angular velocity along with the cart's displacement and velocity as
inputs to calculate the direction and magnitude of the force needed to keep the pendulum upright. A
block diagram of the control system is shown in the figure below.
A disturbance is added to the computed control force to assess the system response. The controller
force acts on the cart body to control the displacement and velocity profiles of the cart mass.
, where
is the error (difference between reference and actual values) on the input signals.
The angular displacement and velocity of the pendulum are obtained by using the AY() and WY()
expressions respectively. The translational displacement and velocity of the cart are obtained similarly,
by using the DX() and VX() expressions.
1. From the Start menu, select All Programs > HyperWorks <version number> >
MotionView.
2. Open the model InvertedPendulum_NoCosimulation.mdl from your <Working Directory>.
Slider Trans Joint Translational joint Translational joint between the cart body
and the ground
Pendulum Rev Joint Revolute joint Revolute joint between the pendulum body
and the cart body
Control Force Vector force The control force applied to the cart body
Output control force Output request Use this request to plot the control force
Output slider Output request Use this request to plot the cart's
displacement displacement
Output slider velocity Output request Use this request to plot the cart's velocity
Output pendulum Output request Use this request to plot the pendulum's
displacement displacement
Output pendulum Output request Use this request to plot the pendulum's
velocity velocity
Pendulum Angular Solver variable This variable stores the rotational velocity
Velocity of the pendulum via the expression VY()
3. In the Run panel, specify the name InvertedPendulum_NoCosimulation.xml for the MotionSolve
model name and click Run.
The results achieved will be used as the baseline to compare the results obtained from co-
simulation.
• The Control_PlantInput element defines the inputs to a mechanical system or plant. For this
model, only one input is defined in the "Plant Input Simulink" solver array. This is set to the ID of
the solver variable that holds the control force from Simulink.
• The Control_PlantOutput element defines the outputs from a mechanical system or plant. For
this model, four outputs are defined in the "Plant Output Simulink" solver array. These are the
pendulum rotation angle, the pendulum angular velocity, slider displacement and slider velocity.
The inputs specified using the Control_PlantInput and Control_PlantOutput elements can be
accessed using the PINVAL() and POUVAL() functions, respectively. Since the Control_PlantInput
and Control_PlantOutput list the ids of solver variables, these inputs and output variables may
also be accessed using the VARVAL() function. For more details, please refer to the MotionSolve
User's Guide on-line help.
◦ Plant Input: A single control force that will be applied to the cart.
◦ Plant Output: The pendulum's angular displacement and angular velocity; the cart's
translational displacement and velocity.
Environment
Value Windows shell Linux shell MATLAB shell
variable
LD_LIBRARY_PATH - <altair>\hwsolvers\motionsolve\bin
\linux64: $LD_LIBRARY_PATH
where <altair> is the full path to the HyperWorks installation. For example, on Windows, this
would typically be C:\Program Files\Altair\<version>.
2. Note that other optional environment variables may be set for your model. See MotionSolve
Environment Variables for more information on these environment variables.
The S-Function libraries for co-simulation with MotionSolve is called mscosimipc – for Inter Process
Communication (IPC) using TCP/IP sockets for communication.
The location of this file needs to be added to the search path of MATLAB for the S-Function to use
mscosimipc.
b) From the dialog, add the directory where the mscosimipc library resides.
<altair>\hwsolvers\motionsolve\bin\win64
a) To add the directory where mscosimipc library resides into the MATLAB search path, at the
MATLAB command line, type:
addpath('<altair>\hwsolvers\motionsolve\bin\<platform>')
Note: You can also create a .m script to make this process more easily
repeatable.
For example, you can set the MATLAB path and the necessary environment
variables using MATLAB commands in a MATLAB (.m) script:
addpath('<altair>\hwsolvers\motionsolve\bin\win64')
setenv('NUSOL_DLL_DIR','<altair>\hwsolvers\motionsolve\bin\win64')
setenv('RADFLEX_PATH',['<altair>\hwsolvers\common\bin\win64')
setenv('PATH',['<altair >\hwsolvers\common\bin\win64;'
getenv('PATH')])
setenv('MS_SERVER_IP_ADDRRESS','192.168.1.123')
To run this command correctly, you will need to setup a few environment variables on Machine
"B". Please see MotionSolve Environment Variables for more information on these environment
variables.
The command "msdaemon" must be issued from the same working directory where the
MotionSolve XML resides. After issuing this command, you have setup MotionSolve in a "listening"
mode. The co-simulation will start whenever the simulation is started from Simulink.
2. On Machine "A", click Simulation > Start to start the co-simulation.
Simulink uses ODE45 to solve the Simulink model. From this, the co-simulation should begin and
Simulink will wait to connect to the MotionSolve model.
After starting the simulation in Simulink, MotionSolve will connect with the Simulink model and
the subsequent co-simulation will result in an output .mrf file for post-processing.
3. Set the Scopes in the Simulink model to display the results.
4. Check the .log file to make sure no errors or warnings were issued by MotionSolve.
3. Click the file browser and load the InvertedPendulum_NoCosimulation.mrf file. This was the
baseline result created by running MotionSolve by itself.
4. In the Page Controls toolbar, create two vertical plot windows.
5. Select Marker Displacement for Y-Type, REQ/70000004 Output slider displacement (on
Slider cart) for Y Request, and DX for Y Component to plot the cart's translational displacement:
8. Click the file browser icon and load the InvertedPendulum_Cosimulation.mrf file. This was the
co-simulation results run with Simulink.
9. Select Marker Displacement for Y-Type, REQ/70000004 Output slider displacement (on
Slider cart) for Y Request, and DX for Y Component to overlay the plot in the left window.
10. Select Marker Force for Y-Type, REQ/70000002 Output control force- (on Slider cart) for Y
Request, and FX for Y Component to overlay the plot in the right window.
Both the signals match as shown below.
Figure 214: Comparison of the Cart Displacement and Cart Control Force Between the Two Models
The blue curves represent results from the MotionSolve-only model and the red curves represent
results from the co-simulation.
Appendix
For remote co-simulation, there are two options to installing MotionSolve on the machine where
Simulink is installed:
• Option 1: Fully install MotionSolve on Machine A, just like Machine B
• Option 2: Install a partial set of libraries on Machine A
If you exercise Option 2 above, then the list of files that need to be copied/installed on the machine
where Simulink is located include the following:
mscosimipc.mexw64 mscosimipc.mexa64
msdaemon.exe msdaemon
nuclient.dll nuclient.so
pthreadVC2.dll
Also, when using Option 2, you can copy the above files to any folder of your choice, for example, ../
motionsolve/remote_cosimfiles/. In this case, the environment variables to set in Simulink will
change based on the table below:
LD_LIBRARY_PATH - ../motionsolve/
remote_cosimfiles:
$LD_LIBRARY_PATH
Activate is a software solution for multi-disciplinary, dynamic system modeling and simulation. The
software is especially useful for signal-processing and controller design that requires both continuous-
time and discrete-time components.
A co-simulation enables MotionSolve and Activate models to communicate with each other during
simulation. An ideal use case for co-simulation is the development of a control system for a multibody
dynamics model.
In MotionView you will create the quadrotor frame with 4 superblades and add the rotors motions. A set
of forces will be used to represent the wind disturbance.
Activate, through co-simulation with MotionSolve, will implement a controller to impose altitude and
direction in quadrotor trying to compensate against the wind effect.
Exercise
Copy the Quadrotor_start.mdl, rotor.h3d, shaft.h3d, superblade.h3d and
Quadrotor_Control_Start.scm from <installation_directory>tutorials\mv_hv_hg\mbd_modeling
\motionsolve\cosimulation\activate> to your <working directory>.
To connect these 9 bodies there are 4 fixed joints connecting the rotors with the vehicle and 4
revolute joints connecting the propellers with the rotors.
2. For Label and Variable, enter Prop_Left_Rotation and mot_Prop_Left_Rotation, and click OK.
Figure 215:
3. From the Connectivity tab, double-click Joint. Select Propeller_Left and click OK.
4. Change the Property to Velocity.
Figure 216:
In a quadrotor, the velocity of the propeller is defined by the controller of pitch and roll of the
vehicle.
To define the velocity value of each propeller motion, create three solver variables that are use
further in the co-simulation.
Figure 217:
Figure 218:
d) Repeat the steps a-c to create the Pitch and Roll solver variables.
Label Variable
Roll_Command sv_Roll_Command
Pitch_Command sv_Pitch_Command
`VARVAL({sv_Throttle_Command.idstring})+VARVAL({sv_Roll_Command.idstring})`
d) Repeat the steps above for Propeller Right, Front and Rear, following the table entries below:
Motion Expression
Prop_Right_Rotation
`VARVAL({sv_Throttle_Command.idstring})-
VARVAL({sv_Roll_Command.idstring})`
Prop_Front_Rotation
`-VARVAL({sv_Throttle_Command.idstring}) -
VARVAL({sv_Pitch_Command.idstring})`
Prop_Rear_Rotation
`-VARVAL({sv_Throttle_Command.idstring})+
VARVAL({sv_Pitch_Command.idstring})`
Note: The lateral propellers (left and right) control the Roll of the vehicle and
the vertical propellers control the Pitch. The signal difference in the expressions
determine the rotation direction of the quadrotor.
Figure 219:
The wind disturbance is represented as a combination of torques in the X and Y axle applied at the
vehicle center.
(12)
Where,
= Thrust force
= Thrust factor (Defined considering the propeller geometry, air density,m and spin area. For this
analysis Tf= 2.1998e-5).
Figure 220:
Figure 221:
Figure 222:
f) From the Trans Properties tab, change Fz to Expression and enter the expression: ` `
Figure 223:
g) Repeat the steps to create the thrust force for the right, front, and rear.
Thrust Right
Label Thrust_Right
Variable frc_Thrust_Right
Body Rotor_Right
Point Right_Motor_Center
Fz Expression `2.1998e-5*ABS({j_Propeller_Right.WZ})^2`
Figure 224:
Thrust Front
Label Thrust_Front
Thrust Front
Variable frc_Thrust_Front
Body Rotor_Front
Point Front_Motor_Center
Fz Expression `2.1998e-5*ABS({j_Propeller_Front.WZ})^2`
Figure 225:
Thrust Rear
Label Thrust_Rear
Variable frc_Thrust_Rear
Body Rotor_Rear
Point Rear_Motor_Center
Fz Expression `2.1998e-5*ABS({j_Propeller_Rear.WZ})^2`
Figure 226:
3. To save your model, click Save As and save it with the name Quadrotor_tutorial.mdl
Altitude sv_Altitude
`DZ({m_Vehicle.idstring})`
Roll_Angle sv_Roll_Angle
`AY({m_Vehicle.idstring})`
Pitch_Angle sv_Pitch_Angle
`AX({m_Vehicle.idstring})`
PosX sv_PosX
`DX({m_Vehicle.idstring})`
PosY sv_PosY
`DY({m_Vehicle.idstring})`
VX sv_VX
`VX({m_Vehicle.idstring})`
VY sv_VY
`VY({m_Vehicle.idstring})`
3. Create two solver arrays, ControlInput and PlantOutput, to communicate with Activate.
a) Right-click SolverArray from the toolbar to display the Add SolverArray dialog.
b) For Label, enter ControlInput.
Figure 227:
Figure 228:
f) Right-click SolverArray from the toolbar to display the Add SolverArray dialog.
g) For Label, enter PlantOutput.
h) For Variable, enter sa_PlantOutput and click OK.
i) From the Properties tab, change the Array type to Plant Output and click Append 6 times to
append 6 more signals.
j) For the seven solver variables, select the Roll_Angle, Altitude, Pitch_Angle, PosX, PosY,
VX, and VY variables in this order.
4. Save your model.
Note: The controller is not yet connected to the model, so the input force and torque
are zero.
Figure 229:
These three sections of controls defined by seven PIDs are the plant input for the MBS model. In
MotionView, it's defined as Roll_Command, Throttle_Command and Pitch_Command.
The plant output, Roll_Angle, Altitude, Pitch_Angle, PosX, PosY, VX, and VY, are input for the PID
controls.
For example, in the X position target control, you will see three inputs which come from the plant
output (PosX, VX, and Roll Angle).
Figure 230:
4. To enable co-simulation between Activate and MotionSolve, from Activate, select File >
Preferences > Paths. In the dialog that is displayed, define the MotionSolve and MotionView
license paths.
Figure 231:
5. From the Palette Browser, select Palettes > Activate > CoSimulation, and drag-and-drop the
MotionSolve block into the current diagram and connect the blocks.
Figure 232:
6. From the diagram, double-click the MS Plant block. From the dialog that is displayed, define the
following block properties:
a) XML or MDL input filename: Browse the path to your MotionView .mdl model or MotionSolve
.xml file (Quadrotor_tutorial.mdl or Quadrotor_tutorial.xml) by clicking the file
selector.
Note: Activate allows you to define either MDL or XML as the input for co-
simulation with MotionSolve. When you choose MDL as the input file name, MDL
is converted to XML on run time so you may notice a delay as the co-simulation is
beginning.
b) MRF output filename: Specify the path for the output MRF file (Quadrotor_tutorial.mrf).
Use the forward slash, /, in your path definition.
c) Direct feed through: Clear (default) the checkbox. If the object is selected and the simulation
runs and encounters an algebraic loop, the option should be cleared to break the algebraic
loop.
The following parameters are populated automatically after you load the input model, *.mdl or
*.xml:
• Inputs Row Size: The value 3 indicates that three signals are supplied from Activate to the
MotionSolve model. These signals correspond to the solver array PlantInput, with variables
Roll_Command, Throttle_Command and Pitch_Command.
• Outputs Row Size: The value 7 indicates that the MotionSolve model is sending out seven
signals from one port, which is why the Demux block is added to separate the signals.
The signals correspond to the solver array PlantOutput with variables Roll_Angle, Altitude,
Pitch_Angle, PosX, PosY, VX and VY.
Figure 233:
7. Click and drag to connect the output of the block Mux to Control Input of the MS Plant. Similarly,
connect the Plant Output end of the MS Plant to the input end of Dmux. All required blocks are
now present and connected in the modeling window.
Figure 234:
8. From the ribbon's Simulate tool group, select Setup tool. From the Simulation Parameters
dialog, in the Final Time field, enter 12 so that your simulation runs for twelve seconds.
Figure 235:
Note: Since Activate is the master, or calling, solver in this co-simulation scenario,
if the simulation end time in Activate is different than the MotionSolve simulation end
time, the MotionSolve simulation end time will be modified at run time to match the
end time specified in the Activate dialog above.
10. Launch HyperView and animate the Quadrotor_tutorial.h3d file to see the quadrotor behavior.
Figure 244:
Figure 245:
11. Before exiting the applications, save your work in Activate as quadrotor_complete.scm.
B
building a C++ user subroutine DLL using Microsoft® Visual Studio® 172
building a FORTRAN user subroutine DLL using Microsoft® Visual Studio® 173
building and analyzing a simplified model 180
building the shared library 168
C
checking the stability of a closed loop system 207
comparing the MotionSolve-only results to the co-simulation results 196, 248
connecting MotionSolve with Activate 261
consolidating and renaming the suspension assembly bodies 42
contact overview via H3D 21
converting C sub into Python sub 175
creating a fixed joint between two non-coincident markers using Templex 56
creating a geometry object 139
creating a model 130, 135, 143, 153
creating a template to define the sequential simulation 57
creating and simulating flexible LCA 64
creating control inputs and plant outputs 259
creating joints and motion 14
creating joints and spring damper 48
creating joints, markers and sensors 53
creating markers 131, 131, 138
268
creating output requests and rerunning the model 37
creating points 45
creating RBE2 spiders 66
creating requests 146
creating the MBD model of the car door 89
D
defining a motion to retract the landing gear 32
defining a template to run the sequential simulation 35
defining an extension motion for the landing gear 34
defining contact between the colliding geometries 15
defining markers for geometry 144, 144
defining points 137
defining stress/strain set in OptiStruct 75
defining the contact force 132
defining the model set in OptiStruct 76
defining the plant in the control scheme 190, 242
designing a control system in MATLAB 207
determining the stability of the open loop model 204
F
flexible body dynamics tutorials 60
frequently asked questions 170
G
generating a plot 147
generating the flexbody using flex prep 87
I
implementing the control force in MotionView 207
import cad geometry into MotionView 11
integrating the flexbodies into your MBD model 79
invoking FlexPrep in batch mode 73, 73
L
load the model in MotionView 223
loading the CAD file into MotionView 39
loading the msolve module 130, 135, 143, 150
loading the rotor model 199
M
manually yplotting other output requests 27
modeling differential equations 182
modifying the ACF file 96
269
modifying, compiling and linking the code to create the DLL 216
MV-1010 summary 28
MV-1010: 3D Mesh to Mesh Contact Simulation 10
mv-1011: extension and retraction analysis of the main landing gear of an aircraft 29
MV-1024: Using User Subroutines in MotionSolve Models 158
MV-1035: Importing CAD or FE into MotionView 39
MV-1051: Understanding Sequential Simulation 53
MV-2010: Flexbody Generation using Flex Prep and OptiStruct 64
MV-2020: Using Flexbodies in MBD Models 79
MV-2021: Simulating an Automotive Door Closure Event 86
MV-2035: Solving Flexbody ADM/ACF in MotionSolve 95
mv-3000: doe using MotionView-HyperStudy tutorials 100
mv-3010 optimization using MotionView - HyperStudy 124
MV-7000: Modeling Differential Equations Using MotionView and MotionSolve 180
MV-7001: Building User Subroutines in Altair MotionSolve 165
MV-7002: Co-simulation with Simulink 187
MV-7003: Simulating a Single Input Single Output (SISO) Control System Using MotionView and MotionSolve 199
MV-7004: Inverted Pendulum Control Using MotionSolve and MATLAB 203
MV-7005: Linking Matlab/Simulink Generated Code (Simulink Coder) with MotionSolve 210
MV-7006: Python UserSub for MotionSolve 174
MV-7008: co-simulation with AcuSolve 220
MV-7009: Co-simulation with Simulink - IPC Approach 237
MV-7010: Co-Simulation with Activate - Quadrotor Control 252
MV-9000: Bouncing Ball Tutorial 130
MV-9001: Simple Pendulum Tutorial 135
MV-9002: Slotted Link Tutorial 143
MV-9003: LuGre Friction Tutorial 149
O
obtaining a linearized model 205
opening the landing gear mechanism 30
optimization-doe-stochastics tutorials 99
P
performing the co-simulation 247
plotting the contact forces via ABF 26
post-process the results from the co-simulation 233
post-processing the results 20
preparing the MotionSolve model 210
preparing the Simulink model - generating code 211
R
repeating the co-simulation 195
review the finite element model for the flexible door 86
reviewing the model 252
270
rigid body dynamics tutorials 9
run the AcuSolve executable for co-simulation 232
run the model without co-simulating with AcuSolve 227
run the MotionSolve and middleware executables for co-simulation from the MotionSolve run manager 229
running a dynamic analysis to simulate the retraction of the main landing gear. 34
running a MotionSolve model with the generated DLL 217
running the baseline MotionSolve model 189, 241
running the MBS model in MotionSolve for verification 260
running the model in MotionSolve 185
running the simulation 133, 140, 147, 201
running the simulation and animating the results 58
S
setting up a transient simulation and running the model 19
setting up environment variables 192, 244
setup the co-simulation 193, 245
simulating and animating the model 36
specify the “wet” body that will interact with AcuSolve 225
specifying motion inputs and running the model in MotionSolve 51
specifying source code or object files 166
specifying the output directory 168
specifying the propellers motions 252
specifying the velocity of the propellers 254
step 1: optimization study 125
step 1: study setup 102
step 2: comparing the baseline and optimized models 127
step 2: doe study 111
step 3: approximation 118
U
user subroutines tutorials 157
using an expression to define motion 159
using FlexBodyPrep 65
using PLOTEL elements in OptiStruct 76
using the Microsoft® Developer Studio to build a shared library 172
using the MotionSolve api tutorials 129
using the MotionSolve subroutine build tool to create shared libraries 165
using the MOTSUB user subroutine to define motion 160
using the released DOF method for interface nodes in OptiStruct 78
V
verify the model between MotionSolve and AcuSolve 228
verifying the part creation 138
viewing the controller modeled in Simulink 194, 246
viewing the model and verifying results 69
271
viewing transient analysis results in HyperView by adding external graphics 97
visualizing MotionSolve outputs 25
visualizing the contact forces via H3D 23
visualizing the penetration depth via H3D 22
visualizing the sum total of force at a given region 24
272