Вы находитесь на странице: 1из 53

Managing the CAE Process Contents

Introduction ......................................................................................................2
About This Series ...........................................................................................2
About This Book .............................................................................................2
Supporting Material ........................................................................................3
Product Design and Process Management ...........................................................4
Projects, Practices and Processes ....................................................................4
Processes, Creativity and NPD.........................................................................6
CAE and Process Management ........................................................................7
Summary .......................................................................................................9
Process Management and Customization........................................................... 10
Process Templates ....................................................................................... 10
Process Customization .................................................................................. 11
What Does Customization Involve?................................................................ 12
The Key Questions ....................................................................................... 13
Customization and Programming ...................................................................... 15
A Programming Primer ................................................................................. 15
Customizing HyperWorks .............................................................................. 17
Putting It All Together .................................................................................. 24
The Process Manager....................................................................................... 26
Creating Process Wizards .............................................................................. 26
Anatomy of a Process Template .................................................................... 28
The Folder Structure..................................................................................... 32
Advanced Topics ............................................................................................. 34
Debugging ................................................................................................... 34
Programming Languages – An Abstract View ................................................. 36
Programming – The HyperWorks View........................................................... 38
XML............................................................................................................. 46
Glossary And References.................................................................................. 48
References................................................................................................... 50
Other Resources........................................................................................... 51
Macros on the User Page .............................................................................. 51
Templex and Templates................................................................................ 51

Introduction Managing the CAE Process

About This Series
To make the most of this series you should be an engineering student, in
your third or final year of Mechanical Engineering. You should have access
to licenses of HyperWorks, to the Altair website, and to an instructor who
can guide you through your chosen projects or assignments.

Each book in this series is completely self-contained. References to other

volumes are only for your interest and further reading. You need not be
familiar with the Finite Element Method, with 3D Modeling or with Finite
Element Modeling. Depending on the volumes you choose to read, however,
you do need to be familiar with one or more of the relevant engineering
subjects: Design of Machine Elements, Strength of Materials, Kinematics of
Machinery, Dynamics of Machinery, Probability and Statistics, Manufacturing
Technology and Introduction to Programming. A course on Operations
Research or Linear Programming is useful but not essential.

About This Book

This volume addresses one of the fastest growing areas in CAE – managing
data and processes. Like the other books in this series, it is self-contained.
However, it makes most sense to study these methods either in conjunction
with or after learning the topics addressed in at least one of the other books
in this series.

While a knowledge of any programming language or method won’t hurt, it is

not essential. Our study will be restricted to the HyperWorks context, which
requires a relatively narrow and relatively deep focus. As we will see, the
architecture of a program is usually more important than the programming
itself. Accordingly, a knowledge of the application areas and the HyperWorks
modules will be more useful than a knowledge of programming methods.

Customizing, you will also see, is not for the faint-of-heart.

The various references cited in the book will probably be most useful after
you have worked through your project and are looking for ways to increase
the scope and elegance of the applications you have developed.

Managing the CAE Process Introduction

Supporting Material
Your instructor will have the Instructor’s Manual that accompanies these
volumes – it should certainly be made use of. Further reading and
references are indicated both in this book and in the Instructor’s Manual.

If you find the material interesting, you should also look up the HyperWorks
On-line Help System. The Altair website, www.altair.com, is also likely to be
of interest to you, both for an insight into the evolving technology and to
help you present your project better.

The world has arrived at an age of cheap complex devices of great reliability;
and something is bound to come of it.
Vannevar Bush. in 1945

Processes and Product Design Managing the CAE Process

Product Design and Process Management

We usually think of product design as a creative task. That’s a reasonable
view, since creative is often used to describe someone or something that
has the ability or power to create. But if we interpret creativity as

the ability to transcend traditional ideas, rules, patterns,

relationships, or the like, and to create meaningful new ideas,
forms, methods, interpretations, etc.1

we run the risk of going too far in one direction. There’s another side to
product design, one that emphasizes the need for discipline. All you need to
do is browse through a biography of Thomas Edison to understand the
relevance of this aspect of product design. Edison was, by most accounts,
one of the most prolific inventors in recent times. He held 1,368 patents, is
credited with having said that genius is 99% perspiration, 1% inspiration
and famously observed that “none of my inventions came by accident. I see
a worthwhile need to be met and I make trial after trial until it comes.”

It’s this side of product design that makes the

contents of this book important for designers. Osborn's Seven-Step Model for
Creative Thinking
Without getting caught up in an argument over the
relative importance of the various steps listed by the 1. Orientation: pointing up the
many different analyses of creativity (such as the 7- problem
step model shown in the figure), we will first review 2. Preparation: gathering
the importance of processes in product design, then pertinent data
go on to see how we can use the facilities offered by 3. Analysis: breaking down the
HyperWorks to embed process discipline in the relevant material
design activities discussed in the other books in this 4. Ideation: piling up
series. alternatives by way of ideas
5. Incubation: letting up, to
invite illumination
Projects, Practices and Processes 6. Synthesis: putting the pieces
Most design activities are broken down into clearly together
7. Evaluation: judging the
defined projects. A project has a deadline, one or
resulting ideas
more goals, and a set of resources. Any of these can
change during the lifetime of the project, often From Models for the Creative Process,
because of reasons beyond the control of the by Paul Plsek
project’s sponsors. Project Management is often

which is how the Random House Unabridged Dictionary defines it
Processes and Product Design Managing the CAE Process

seen as a dark art, relying heavily on the skill of the individuals involved in
the management of the project. But Project Management is a skill that can
be studied and learned. Several sectors rely on this, most notably Software
Development and IT Services companies. Certification by the Project
Management Institute (www.pmi.org) is quite widespread.

Experience with multiple projects exposes participants to different ways of

doing things. One of the skills project managers develop is the ability to
recognize which of these various methods is best suited for a given
situation. The Project Manager usually breaks the project down into a series
of tasks, and advises the various teams on how to best go about achieving
their respective goals.

The idea that for every task there is a technique that is more effective than
any other technique is quite widespread in management. Most organizations
develop a series of Best Practices, which are nothing but preferred
techniques for the various scenarios the teams are likely to encounter. While
the concept is attractive, there are three problems from the operational
point of view. The first problem lies in gathering these Best Practices. The
second lies in ensuring that these are made available to all participants in a
usable fashion. The third lies in ensuring that these practices, after all the
effort of collecting them and disseminating them, are actually followed!

A collection of practices that can be applied in sequence to achieve a specific

goal is called a process. Capturing the difference between a process and a
practice is not easy, but one interpretation relies on the fact that projects
are broken into tasks. In this view, the practice is relevant to a task while a
process is relevant to the entire project.

So what has all this got to do with product


The importance of practices and process in

product design becomes clear if we recall that the
success-failure ratios in most industry segments
are quite small. As shown in the figure2, in most
product-design companies the number of
unsuccessful designs far outnumbers the
successful ones. And since design consumes both

Adapted from Stevens, G.A. and Burley, J – “3000 Raw Ideas = 1 Commercial
Success!”, Research Technology Management, Vol 40, #3, pp 16-27
Processes and Product Design Managing the CAE Process

time and money, managers look for ways to estimate and control both.
Processes, of course, are a natural option to try.

Remember that the intention behind the drive for process is to aid and
enhance creativity, which in turn leads to better products. One popular view
of product development is that the three essential ingredients for successful
product design are People, Processes and Technology. An organization that
has good people and good process but poor technology is inefficient. One
that has good people and technology but poor processes is undisciplined,
while one that has good processes and technology but poor people is

Processes, Creativity and NPD

Within the context of New Product Design (often referred Processes are the stuff in
to as NPD) let’s take another look at the stated intention of the proverbial “black box,”
implementing processes – to aid and enhance creativity. the alchemy unseen by
consumers or the
From a manager’s perspective, of course, processes inelegantly termed “end
promise to reduce variations, mistakes, waste and rework: users” who buy
computers, cellphones,
everything a manager could want. Unfortunately, in the
cameras and all manner of
real world, few processes are perfect. Some have digital devices and
drawbacks in their very design, while some suffer because services.
of the way in which they are implemented. But a process
usually brings with it some reduction in flexibility. Process innovations [are]
often invisible to the
The need for a balance between agility and discipline has public, and impossible to
been recognized by the software-community for several duplicate by rivals. Yet
years now3. To understand why such a balance is beneficial successful companies
realize that maintaining
for the design of engineering products, we first need to
competitive advantage
discuss an important question: how exactly do engineers depends heavily on
design new products? sustaining process
It’s a common misconception that NPD means that you
have to start from the very beginning, that you have to G.P.Zachary
break all the rules, that in fact you should assume there The New York Times

A review of “Agile Development” methods is instructive – see, for example,
Processes and Product Design Managing the CAE Process

are no rules at all. In practice, most engineers rely heavily on their

experience to come up with new designs. This is nicely brought out in the

Project Type 1990 2004

True Innovations – products that are new 20.4% 11.5%
to the world
Product lines that are new to the 38.8% 27.1%
Additions to existing product lines 20.4% 24.7%
Improvements and modifications to 20.4% 36.7%
existing products

The fact that “new to the world” products are a relatively small fraction is
interesting. The logical conclusion is that organizations should pay attention
to building and retaining knowledge about how existing products are
designed – in other words, to capture the design methods and approaches
and make these widely available to designers. In other words, to build
design processes.

It’s important, of course, to remember that several products - and indeed,

companies – benefit from designers using methods that are outside
“established” processes. A process, like money, makes an excellent servant
but a terrible master!

CAE and Process Management

The various activities that make up Computer Aided Engineering are an
essential part of the product design cycle – to speed up the design cycle, to
ensure that the products that are designed are of a higher quality, and to
reduce the cost of the final product. The other books in this series cover
some of the elements of CAE – optimization, robustness, manufacturing
simulation, and so on. Broadly, the tasks the designer has to carry out lie in
two categories – the first is model creation, while the second covers
reporting and interpretation of results.

APQC benchmarking study: Cooper, R.G., Edgett, S.J. and Kleinschmidt, E.J.,
“Benchmarking best NPD practices—II: Strategy, resource allocation and portfolio
management”, Research Technology Management, 47:3, May/June 2004, 50-59.
Processes and Product Design Managing the CAE Process

Regardless of the category, many of the tasks are tedious, requiring a

considerable attention to detail. And they are also notoriously error prone. A
report5 on the sinking of an offshore oil platform makes a telling point:

“The post accident investigation traced the error to inaccurate

finite element approximation of the linear elastic model of the
tricell (using the popular finite element program NASTRAN). The
shear stresses were underestimated by 47%, leading to
insufficient design. In particular, certain concrete walls were not
thick enough. More careful finite element analysis, made after the
accident, predicted that failure would occur with this design at a
depth of 62m, which matches well with the actual occurrence at

One way to improve a model is to use a checklist: element-quality checks

are an excellent example of checklists. But suppose, as a result of oversight
or of ignorance, the checklist has not been applied? Even worse, suppose
the designer has neglected to report any assumptions in the model – and
suppose the violation of these assumptions can lead to disaster!

Clearly, the potential impact of CAE-errors can be very high. And, clearly,
the process for CAE is well defined. The missing link is the ability to verify
that the process has actually been followed!

And that is where management of processes comes in. The Dictionary

defines management as the act or manner of managing; handling, direction,
or control. To handle, direct and control effectively, the manager needs to
provide information on the suggested procedure, verify that the procedure
has been followed, and suggest further action based on the results.

Two terms are specifically important in this context.

The first is “Dashboard”. A dashboard is a summary of larger information.

Dashboards are appealing because they make it easy to absorb data, but are
dangerous because, like statistics, what they conceal may well be more
important than what they reveal. And it’s because of this danger that the
second term is as important – “Audit Trail”. The audit trail is the record of
the sequences that led to the information displayed in the dashboard. This
provides the manager the ability to start from the Dashboard, with its easy-

From http://www.ima.umn.edu/~arnold/disasters/, written by D.N.Arnold, of the
University of Minnesotta.
Processes and Product Design Managing the CAE Process

to-absorb information summaries, and walk back all the way through the
CAE process, checking each and every step.

This approach is not just necessary for safer and better product design. In
several countries, the law requires that such design-records be maintained.

From a process management perspective, then, both the decisions taken

and the process knowledge itself should be captured and tracked.

We have seen that

• product design requires both creativity and familiarity with methods

used for to design existing products

• processes and practices serve as aids to product design

• process management is an essential part of implementing this


In the subsequent chapters, we will look at various ways in which these

obvious principles can be adapted to and implemented in a variety of

The most important task for a designer is to “design the right product”. We
cannot supply the answer to that, but we can certainly make it easier to
“design the product right”!

There is nothing so wasteful as doing with great efficiency that which doesn't
have to be done at all.

Customization and Process Management Managing the CAE Process

Process Management and Customization

Processes make very good sense when we use the logic outlined in the
preceding chapter - the holy trinity is “people-processes-technology”. But
the universe is notoriously unpredictable, and people are, if anything, even
less predictable. Given this truth, does it make sense to search for a process
that is applicable or even relevant to widely varying scenarios?

Probably not. Most approaches to process-management leave some room

for localization – that is, changes to the process to account for parameters
that are specific to a particular locale. In the context of computer programs,
customization and templates are commonly used to account for context-
specific requirements. In this chapter we’ll discuss these from an abstract
perspective, before we go on to cover implementation-level details in the
subsequent chapters.

Process Templates
It’s one thing to agree that a process is useful. Actually defining the process
is an entirely different problem. How does one go about identifying the steps
that make up the process? Should a process be created, or can it be built?

There’s a very important distinction between those two verbs, best

expressed by Fred Brook’s when he wrote6:

I still remember the jolt I felt in 1958 when I first heard a friend
talk about building a program, as opposed to writing one. In a
flash he broadened my whole view of the software process. The
metaphor shift was powerful, and accurate. Today we understand
how like other building processes the construction of software is,
and we freely use other elements of the metaphor, such as
specifications, assembly of components, and scaffolding.

Continuing with the “build” metaphor, the search for a suitable process can
be compared with the search for a suitable house.

One alternative is to start from the ground up – a brand new design, chosen
to fulfill specific requirements. This makes sense if you can afford both the

In his article “No Silver Bullet: Essence and Accidents of Software Engineering”. See
Managing the CAE Process Customization and Process Management

cost and the time. And if you have the confidence that what you will end up
with is what you actually want. This is important, unless you’re prepared to
redo it after you see what the result is, incurring further costs and spending
more time before it’s ready for use.

Few house owners are prepared for that risk, so the starting point is often a
set of examples that serve as starting points. Another option is to buy an
existing house and make modifications to suit your preferences.

The same applies to process-definition.

The ground-up approach is to write the process definition from scratch. Not
only is this expensive and time consuming, there’s also the risk that the
questions you’re addressing to define the process are the wrong ones – and
you won’t know it till you implement it. Process templates offer a way out of
this. A process template serves as a pattern or a model, a good starting
point. It is built upon knowledge and experience acquired by others, so
serves as an excellent way to capture process knowledge.

And if the context in which that experience was acquired is not the same as
yours, the answer is easy – just customize it.

Process Customization
Customization, though, involves modifications, and modifications invariably
carry the risk that you’re introducing fresh errors or inaccuracies. To quote
Brooks again,

The familiar software project, at least as seen by the non-technical

manager, is usually innocent and straightforward, but is capable of
becoming a monster of missed schedules, blown budgets, and
flawed products.

To customize or not to customize, then, that is the question. This is never an

easy question to answer. A careful evaluation of the risks and benefits is
called for. That aspect is beyond the scope of this book7. Here we will
assume that the decision to customize has been made, and will look at the
“what” and “how” of process customization – that the “why” has already
been answered.

Interested readers will find Brooks’ The Mythical Man Month worth reading.
Customization and Process Management Managing the CAE Process

Brooks’ description makes the risks clear, but to balance the discussion, the
benefits must also be understood just as clearly. Customized processes can
bring tremendous benefits, if done right, particularly for CAE. Remember
that CAE is repetitive. The analyses involved in the design of products,
whether they are totally new or are modifications of existing designs, are
based on best practices drawn from the experience of engineers and
analysts. As a result, CAE involves a set of tasks with relatively small
variations – the sequence of tasks is often referred to as a workflow. The
ability to capture and automate this workflow can be well worth the

Consider the experience reported by Audi8

One of the greatest benefits of Audi's CAEBench system is the

overall time savings. We assume a time savings per simulation of
about one hour. With 100 simulations per engineer per year and
50 engineers, we get 5000 simulations per year. The time saving
for this example would be 5000 hours per year. This corresponds
to three man-years. Thus the simulation engineer can perform
more simulations, has more time for analyses, can get the results
faster, and therefore has a better technical understanding.

What Does Customization Involve?

Given the risks and benefits of customization, it is essential to understand
what customization involves, in order to take an educated decision.

The word “customization” opens a broad range of possibilities, but common

to all is the fact that there is either an existing application (which represents
the “technology” element of our holy-trinity) or process that is being
customized. Several times, both the application and the process are

Application customization is distinct from process customization, so let’s look

at that first. The most obvious element of application-customization involves
the User-Interface (or UI). This could range from changing the language
used to display prompts, options and messages, to removing menus or
options. The latter is particularly useful for beginners – simplifying the
options reduces complexity and reduces the chance that wrong options will
In CAE Data Management at Audi AG, by Dr. K. Gruber, Dr. U. Widmann, J.
Reicheneder, and J. Eberfeld Sidebar in the MSC-Software's Alpha Magazine, Volume
5 - Summer 2005
Managing the CAE Process Customization and Process Management

be chosen. Most current-day software development practices use modular-

programming techniques. One of the aspects of this approach is the
separation of the user-interface and the internal-logic (or algorithms). This
makes it easier to mask menus or options – the chances that these will
affect the working of the application are minimal.

But application customization can also involve adding commands or menus.

This is more involved. Adding a command or menu means you are
introducing a new algorithm or logic of your own. This means that the
responsibility of testing this new logic is yours.

The easier way to introduce a new command or option is to combine

existing commands or functions. This makes the verification-process easier,
but also restricts you to working with modifications rather than completely
new functions. Provide a completely new capability requires the use of a
programming language, and increases the complexity of the task by several
orders of magnitude.

Now our investigation is almost complete. If you can customize the

application, you can use the application to implement a process. That is, you
can modify the application to restrict the user to the tasks that are a part of
the process, and can at the same time enforce the sequence of tasks that
define the process! And since the process-implementation relies on
application-customization, process-customization is straightforward.

For engineers working on product-design, learning how to customize a

process brings an unexpected and important benefit. The parallels between
process-customization and product-design are striking. The research and
investigations that precede the task, the discipline involved in performing
the task, and the options – remove features, modify features, add features –
with their attendant costs and risks.

The Key Questions

Before we take the next step – the “how” of process customization – let’s
run over what we’ve just discussed.

Why customize?
At the most obvious level, process-customization helps reduce mistakes.
Checklists are common in many engineering areas – aircraft, for instance, go
through rigorous checklists at every landing and before every takeoff. Most
CAE applications provide a broad range of checks, such as the element-free-
Customization and Process Management Managing the CAE Process

edges checks in HyperMesh. Given a series of checks that are appropriate

for your specific problem, you can reduce error by tailoring the application to
reduce the number of available options – restricting the number of options
reduces the chance that the designer will forget to carry out a check.

Traceability is the next obvious benefit. Just as an aircraft’s cockpit-voice-

recorder is used to investigate accidents, you can customize the application
to record actions performed by the designer, so that a retrospective
evaluation can be performed.

The third obvious benefit is the reduction in time to carry out a set of tasks,
as outlined above in the Audi case.

Less obvious, but often even more beneficial, are the improvements in
product quality that the use of a good process can bring. Design
methodologies such as Design For Six Sigma (DFSS) consider the link
between process quality and product quality to be an axiom. The Law of
Quality states that “the quality of a product is largely determined by the
quality of the process that is used to develop and maintain it.”

Why not customize?

The flip side of the equation, of course, is mainly the cost. Successful
process-customization demands a knowledge of the application, the process,
programming techniques, and testing methods.

A second factor on this side of the equation is time. Even if you are willing to
afford the cost, will the program be ready before the need has expired?

We’ll round up this chapter by turning back to Fred Brooks again. In the
article cited above, he writes “The most radical possible solution for
constructing software is not to construct it at all”. We’ll spend the rest of this
book looking for less radical solutions!

Excellence in any department can be attained only by the labor of a lifetime; it

is not to be purchased at a lesser price
Samuel Johnson

Managing the CAE Process A Primer on Programming Approaches

Customization and Programming

We’ve addressed the “why” and “what” of process customization, but have
one task left before we can study implementation-details. We must review
the “how”.

The intention of this chapter is to provide a brief description, not a complete

reference. There are two reasons for this. The first, of course, is that there
are numerous references that address specifics in great depth9. Further,
learning programming is like learning swimming. Reading about it is not
enough – you actually have to get in the water.

A Programming Primer
Programming languages are of two different types10: systems programming
languages and scripting languages.

C++, C and Java are examples of systems programming languages. These

are intended for general-purpose usage. You can use them to build anything
you want, but this also means that you have to build everything you want!

Languages like Perl, Python, Visual Basic and Tcl are scripting languages.
These are task-specific. Perl, for example, is designed specifically for text-
manipulation – the name itself stands for Practical Extraction and Reporting
Language. It would not be your language of choice for numerical

Scripting languages are widely used to “glue” applications together. They

are easier to learn, and allow for more rapid application development. They
also rely on different programming techniques. Systems programming
languages focus on building data structures and algorithms from scratch.
Rare indeed is the C-programming student who has not struggled with
powerful but abstract concepts like function-pointers and dynamic-memory-
allocation. By contrast, scripting languages rely on an available set of
commands to take care of the low-level work. Since many details are
handled automatically, we often say that they are at a higher level.

Some of these are listed at the end of this book.
Purists will rightly point out that there are other types too – such as Assembly
A Primer on Programming Approaches Managing the CAE Process

One major difference between system-programming and scripting languages

relates to typing – that is, the distinction between types of data such as
alphanumeric, floating-point, and so on. At the basic level, of course,
computers are type-independent because any memory location can hold any
type of data. Languages such as C, however, are strongly typed. This means
that each variable in a program can hold only a specific type of data.
Languages such as Tcl, on the other hand, are type-less. A variable can hold
either a string or an integer, for instance. This removes restrictions or a
priori assumptions on the type of data the program expects, and is a very
useful feature when gluing multiple applications together.

To illustrate the advantages of a scripting language, consider the code

required to create a button on the screen that displays some text and prints
a message when clicked. In Tcl, the command would be

button .b -text Hello! -font {Times 16} -command {puts hello}

The equivalent code in Java or C++ are dramatically longer, as illustrated in

the excellent article “Scripting: Higher Level Programming for the 21st
Century” by John Ousterhout11.

To take advantage of this, applications need to be scriptable. This means

that the application should be controllable by a program, not just be a
person using a keyboard and mouse.

Strongly typed programs have the advantage that errors in logic can be
trapped at compile-time, when the compiler reads the source code and
checks for syntactical errors. Scripting languages tend to be interpreted, not
compiled, which means errors often occur at run-time. As a result, testing a
program becomes harder. This leads to an important point: because of the
testing constraints, scripting-languages are mainly used for smaller
programs, while systems-level languages are preferred if the program is
large and complex.

Remember, of course, that the choice is rarely an either-or choice. Very

often, you can use both! System level languages can be used to create
components such as Java Beans or Visual Basic Controls, and scripting
languages can be used to rapidly and easily assemble these.

See http://home.pacbell.net/ouster/scriptextra.html. Prof.Ousterhout, of course, is
the creator of Tcl and Tk.
Managing the CAE Process A Primer on Programming Approaches

Scripts are particularly useful to implement Graphical User Interfaces (GUIs).

One of the reasons for this is that the user-interface often undergoes more
rapid changes than the underlying computational-algorithms that manipulate
data in response to user interactions. The separation between the user-
interface and the “core-functions” is a common facet of most programming

The phrase object-oriented is commonly encountered in discussions on

programming. An object-oriented language is one that emphasizes the
relationships between objects. This is intended to promote reuse of the
objects – the programmer’s principal focus is on creating objects, and
defining and manipulating the relationships between them. The properties of
the object itself are taken for granted. Objects themselves are instances of a
class. Once the classes have been defined, the programmer only needs to
instantiate the object – that is, create an object that has the characteristics
of the class it belongs to. Classes can be derived from other classes, thereby
creating a class hierarchy, much like the hierarchy-of-species taught in
middle-school biology.

Scripting languages can be object-oriented too – Python is an excellent

example. But the benefits of object-oriented languages are still debated,
decades after they were introduced into mainstream usage. Similarly,
programming methodologies are the subject of widespread debate and
constant development. One approach that is favored, and particularly
suitable for process-customization, is the iterative method. In this approach
(typified by agile, extreme-programming or XP, scrum, etc.) the system is
first made to run, even if it does nothing useful except call dummy
subprograms. Then, step by step, it is fleshed out, by adding and testing the
dummy functions.

Finally, if an API (Application Programming Interface) provided by the host

application, these can be used to enhance customization, as will be
described later.

Customizing HyperWorks
The various modules that make up HyperWorks – HyperMesh, OptiStruct,
HyperView, etc. – cover all the methods outlined above. We’ll review these
in order of increasing complexity and power before we go on to study the
framework that we’ll use to bring all these together to address process-

A Primer on Programming Approaches Managing the CAE Process

A macro is a way to automate repetitive tasks. The macro can be assigned
to a menu or icon, so that a single click results in the execution of the entire
set of command. At its most basic, a macro is just a set of commands,
offering no options to add logic such as if-then-else or do-while constructs.
But macros can be combined with the other customization options, which
means that their power can be extended considerably.

Understanding two files can go a long way towards getting started with
macros. The first of these is command.cmf – it’s a text file in which
HyperMesh stores every command you execute during your HyperMesh
sessions. It’s importance lies in the fact that the recommended way to
create a macro is:

• start HyperMesh

• execute the set of commands that you want to include in the


• open command.cmf and copy the section that relates to these


• create a text file12 and type in


• between these two lines, paste in the lines copied from

command.cmf and save the file (the recommended extension is

This record-and-modify procedure makes it easier, since you do not need to

remember the syntax of each command – just perform the task in
HyperMesh and the corresponding commands are stored in the file

The next important file is userpage.mac. This is the file HyperMesh refers to,
to decide which commands must be displayed on the user-menu page,

You can use any text editor such as notepad for this, but will be better off with
an editor like notepad++ (http://notepad-plus.sourceforge.net/uk/site.htm)
Managing the CAE Process A Primer on Programming Approaches

which is the page that’s displayed when you click on the “User” button on
the Utility Menu. To assign your macro to a button on the user-page, you
edit this file and add a line of the form

*createbutton(5,"Test",20,4,6,MAGENTA,"Test Macro", "Sample")

From this line, HyperMesh concludes that the button must be created on
page 5 of the Utility Menu, with the word “Test” displayed on the button.
The button is placed at row 20, column 4, and has a width of 6. The button
is colored magenta and displays the words “Test Macro” as help when the
mouse hovers over the button. Finally, when the button is clicked, the macro
named sample is called. Remember that the macro gets its name from the
*beginmacro command.

And how does HyperMesh know which file the macro’s commands reside in?
One option is to paste the entire macro in the file userpage.mac itself, but
this can get messy. A better option is to use the command
*includemacrofile("filename.mac") where filename.mac contains your

You can call one macro from another, using the *CallMacro( )
command13. This allows you to create a standard set of macros that can be
reused. A complete list of all commands available for use in macros is in the
on-line documentation under the section titled Alphabetical List of
HyperMesh Commands. Since there are more than 1600 commands, this is
best treated as a reference section, to look up for details on the commands
you’ve recorded.

Macros can also be run using the Files / Load / Command file menu.

The Tcl Interface

The record-and-edit sequence means macros are easy to create, but they’re
relatively limited. What if you want to build a specific user interface, or
implement logical processing? HyperMesh comes with an interpreter for
Tcl/Tk, a popular scripting language.

Tk (short for Tool Kit) provides functions like the *button command we saw
above, while Tcl, short for Tool Command Language and often pronounced
“tickle”, is used to implement programming logic. Some essential elements
of Tcl are covered later in this book, but the important point for us is that

Macros are not recursive – a macro cannot call itself!
A Primer on Programming Approaches Managing the CAE Process

Tcl can be embedded in macros, thereby making the simple macro almost
infinitely extensible!

Tcl programs, usually called scripts, can also be run from the command
window within HyperMesh. To execute the program in the file sample.tcl,
you would type Source sample.tcl in the command window.

In addition to command that are part of all standard Tcl implementations

(such as puts to print a string of text), HyperMesh provides an API for Tcl
developers. This consists of a set of commands that are specifically tailored
to permit access to the HyperMesh database itself. This means that you can
use Tcl to access, and therefore manipulate, everything that’s stored in the
“.hm” file! These HyperMesh specific commands, of which they are several
hundred, always start with the letters hm_. For instance, the command
hm_usermessage displays a string of text on HyperMesh’s message-bar.

The online documentation contains a complete list of these commands in the

section titled Tcl/Tk Commands.

The Tcl API is packaged at a higher level as the HyperWorks Automation

Toolkit – see What is the HyperWorks Automation Toolkit in the online
documentation for details.

Earlier in this chapter, we saw that one of the reasons that scripting
languages such as Tcl are easier to use than system-programming
languages like C is because they are less general in scope.

Templex, an interpreter for a programming language that is specific to

HyperMesh, provides a similar advantage over Tcl. Much less general-
purpose than Tcl, it is intended specifically for mathematical functions and
text-processing. Templex functions, usually stored in files with the extension
“.tpl”, can be called by Tcl scripts. Likewise, Templex programs themselves
can call Tcl scripts using tclevalfile(filename.tcl) or tcleval(tcl

Templex programs are often referred to as templates14, and are remarkably

strong at processing text files. They are commonly used to translators – for

Not to be confused with process-templates!
Managing the CAE Process A Primer on Programming Approaches

instance, HyperMesh itself uses the Templex interpreter to translate Finite

Element data from and to HyperMesh.

For a complete list of Templex commands, look up the online documentation

under the section titled Templex Statements. The last chapter of this book
contains a brief summary.

The methods described above are largely limited to the HyperMesh-universe.
CAE users, though, usually have to deal with many more applications. In
most scenarios, at the very minimum the designer also has to work with at
least one CAD system and a document or data-management system which is
usually built around an RDBMS. Further, the Bills-of-Material (BOM) is
commonly used to define the product structure, as shown in the figure

Most CAE processes involve considerable inter-application communications,

and the process customization task may involve programming the other
applications too. Not all applications, of course, support Tcl. There aren’t
many CAD applications that have built in Tcl interpreters or that provide an
API for Tcl. Many, however, support Java and other system-programming

To make it easier to interface with such applications, HyperMesh provides a

Java API too.

You could, of course, program the other application using whichever

programming language its API supports, and use Tcl or Templex to
customize HyperMesh. But Java also provides several other advantages,
such as the ability to package and distribute your applications as Java
A Primer on Programming Approaches Managing the CAE Process

Beans, strong support for inter-process communications using sockets,

support for SQL to interface with RDBMS’, support for SOAP, and so on.

Using the Java API, you can build standalone applications that can access
HyperWorks databases, or applications that run within HyperWorks
applications – you can add commands to the menus or toolbars too. The
online documentation provides details on the Java API in the section titled
Development Using Java.

Other Programming Languages

In addition to Java, HyperMesh also provides an API for C or C++
programmers. You can write your own C or C++ programs and link them
with libraries supplied with HyperWorks to access the databases. Similarly,
support for Fortran is provided too. Look up the online documentation for
details on these, under the sections Using the HyperMesh C Libraries and
User Subroutines and General Subroutines.

Batch Meshing
Generation of finite element meshes is one of the most time consuming
tasks in Finite Element Analysis. Not only is the task laborious and repetitive,
the meshes very often have to conform to fairly specific requirements. For
instance, OptiStruct/Analysis requires that the aspect ratio of triangular
elements be less than 500, and recommends that the value be less than 50.

The Batch Mesher is an application that addresses this. Unlike the options
described above, the Batch Mesher is not a new programming interface. It’s
an application in its own right (you start it just as you would start the other
HyperWorks Applications). But since you can use it to automatically import
geometry, cleanup the geometry, mesh, and check element quality, it can
play an important role in process customization.

Like the other customization options described above, the Batch Mesher
allows you to mix and match customization options – you can, for instance,
write Tcl scripts for the Batch Mesher, as described in the online
documentation. In fact, you should look at the files in the batchmesh
directory for an excellent example of how the techniques outlined above can
be used to build applications.

A discussion of the Batch Mesher is well beyond the scope of this book.

Managing the CAE Process A Primer on Programming Approaches

The GUI Toolkit

This toolkit, like the Batch Mesher, is a standalone application, but unlike the
Batch Mesher it’s very much a customization tool! If you want to create
widgets – gadgets like buttons that appear in windows – it’s a good idea to
use the examples in the folder \hw\tcl\hwt as a starting point.

Several of the files in this folder have the extension “.tbc”. This means they
are Tcl scripts that have been compiled. While Tcl is normally implemented
as an interpreted language, you can compile Tcl scripts and distribute the
“.tbc” files instead of the “.tcl” files. The main advantage of this is that you
can protect your source code. See http://sourceforge.net/projects/tclpro/ for
details on one such compiler.

Keyboard Shortcuts
You can assign commands to keys using the Preferences menu. For
instance, to run a Tcl script whenever the key “j” is pressed, enter
*evaltclstring scriptname next to the key “j”.

The Startup Sequence

To round out our discussion on customization options for HyperWorks, we
need to understand what happens, and in what order, when HyperMesh
starts. Understanding this can help you come up with innovative ways to
wrap your applications into HyperMesh.

To start HyperMesh, you run hmopengl.exe15. You can add arguments at the
command line when you run HyperMesh. For instance, you could choose to

hmopengl filename.hm

if you want HyperMesh to open filename.hm when it starts. Look up the

section titled Start-up Options in the online documentation for a complete
list of the various command-line arguments.

Once the command is run, HyperMesh looks for several files. It first looks in
your start-up directory for each file. If it doesn’t find the file, it looks in the
installation directories. The files that are important for us are:

You could run hmbatch to start HyperMesh in batch mode.
A Primer on Programming Approaches Managing the CAE Process

• hm.cfg – affects a broad range of behavior, including fonts used

for the menus, the cursor size, and whether or not to display
Utility menu

• userpage.mac – as described above, this file contains buttons

for macros

• hmmenu.set – determines which menus to show in the menu-

pages. Normally, you would use the build menu panel to add or
hide menus, after which HyperMesh creates this file in your
startup directory. This file also stores the user profile you used
in your last session. If you want to restore the default settings,
just delete this file from your startup directory.

• hmexec – this is a command file that is run whenever

HyperMesh starts. You can copy lines from command.cmf and
paste them in this file if you want to perform any tasks
whenever HyperMesh starts.

• hm.mac – this file contains *includefile commands. You

could edit this file if you want to hide or change complete macro

• hmcustom.tcl – use this if you want HyperMesh to run a Tcl

script on startup

• hmsettings.tcl - HyperMesh uses this file to record various GUI

settings for each user, such as tab locations
(left/right/both/none), tabs which are visible (e.g. model or
include browser), key bindings, recent files imported and recent
files loaded. HyperMesh creates this file automatically when
upon exiting the program. Hmsettings.tcl should not be edited
and its format will change between releases. However, deleting
this file can restore your HyperMesh settings to the default state
if you encounter problems within the HyperMesh user interface
that you cannot rectify by any other means.

Putting It All Together

Most of the previous pages have referred to HyperMesh, but the techniques
outlined above are, in general, applicable to all HyperWorks applications.
Remember that our goal was not to cover all customization methods

Managing the CAE Process A Primer on Programming Approaches

involved, but to provide an overview of the various methods available. All

the methods described in this chapter are applicable to any and all of the
HyperWorks applications. Some applications provide special methods (such
as plot macros and statistical templates for HyperGraph).

All these provide a wealth of options, and this can sometimes be

overwhelming for a beginner. Presented with all these options, we can
understand why Geoffrey Chaucer fretted “the lyf so short, the craft so long
to lerne”.

The rebuttal, of course, lies in the methods we have discussed earlier –

templates and iterative programming. The Process-Management framework,
which we will study in the next chapter, addresses just this.

The fact that the man who gave the world electric light, motion pictures,
talking machines, and the Edison storage battery was responsible for this
utterly useless device should encourage inventors whose first attempts have
George Lee Dowd Jr
in Popular Science Monthly,1930, on Edison’s unsuccessful Helicopter

The Process Manager Managing the CAE Process

The Process Manager

The HyperWorks Process Manager (HWPM) is an application designed
specifically for process-implementation. Making use of any or all of the
customization options outlined in the previous chapter, you can modify or
create a User Interface to guide the user through processes, code in any
logic necessary to implement the process, and even ensure that the process
is adhered to using a “Wizard” interface similar to that used by

About the only thing you cannot do with HWPM is document the workflow in
the first place. It’s a truism that a process that is not documented cannot be
automated, so you must identify the workflow and associated practices
before you get started with HWPM.

Creating Process Wizards

Process Driven Workflows are intended to deliver the benefits we’ve already

• standardization of CAE processes – they capture established

procedures and ensure that other designers / analysts are following

• increase the efficiency of a CAE task – not only by reducing or

avoiding common mistakes, but also by providing guidance on what
choices are recommended at every fork in the modeling-road

• audits of earlier efforts – by maintaining a trail or log of the process

• integration with other elements of the design-cycle – by automating

tedious communications with other applications

The use of “wizards” to guide users through complex tasks is a widely

accepted approach. The introduction into consumer-software probably
started with Microsoft’s Access in 1992, and is so widespread today that it is
hard to find an application that does not use this approach in some form or
the other.

See CAE and Design Optimization – Advanced
Managing the CAE Process MBD Simulation with HyperWorks

The most common implementation is to view the process as a tree, with

branches. At each junction, you decide which branch you want to follow –
the choice automatically decides which further branches you can navigate
to. Not all tasks, of course, can be broken down so cleanly, leading to some
level of objection to this approach. Advanced users often find the restriction-
of-choice restrictive, while beginners usually benefit from the reduced

What is unarguable is that the design of the process has a critical impact on
its usability. In general, resist the temptation to write an all-encompassing
process that will endure for all time. If you find this hard to do, a quick
review of Shelley’s Ozymandias is strongly recommended!

The iterative approach is a better idea. Allow for the fact that the process
will evolve with usage, and ensure that your design provides for easy and
rapid modification. Also ensure, of course, that you have a well-defined test-
bed that evolves along with the process itself.

HWPM takes this approach. It provides two distinct modes of operation.

One, the Process Studio, is where you design and maintain your process.
The other, the Process Manager, is what you distribute to users.

The Process Studio is the “authoring” part of HWPM – it’s an IDE (Integrated
Development Environment) for the Process Manager. You use it to create
new processes by building user interfaces and logic, or you can use it to
modify existing processes.

The Process Studio can be run from within the Process Manager, but it’s
most often used independently as a standalone application. Of all the
customization options outlined in the previous Chapter, the ones most often
used with HWPM are the Tcl API and the Java API.

In addition, HWPM provides an API called the FrameWork which is

particularly useful for Java development. Using this, Java Beans can access
the various classes provided by the FrameWork.

The Process Manager can be used either in batch mode or in the more usual
interactive mode. In the latter case, you would start the Process Manager
from within a HyperWorks application and first select the process you want
to run. Once you choose, it then reads the process-definition and uses a
tree-structure that guides you through the process by

The Process Manager Managing the CAE Process

• showing you the various steps in the process

• tracking the status of each step – for instance, your process may
require that some steps be prerequisites for others. In this case, the
Process Manager changes the “availability” of steps based on the
complete / incomplete status of the prerequisite steps. One other
advantage is that it is a lot easier to stop and restart complicated
process – the Process Manager remembers what you were doing
and restores the state of the application.

• providing facilities to enter / display / modify data associated with

each step. Obviously, these user-interface options are limited only
by the creativity of the programmer.

The easiest way to understand how the Process manager works is to dissect
a sample application.

Anatomy of a Process Template

Sub-modeling is a common approach in linear finite element analysis. The
analysis is first run on a relatively coarse mesh, then a sub-set of this mesh
is chosen for the next analysis. The results of the first analysis are applied as
boundary-conditions to the sub-model and a finer mesh can be used without
increasing the solution-time since the domain is a lot smaller.

This is easy enough to understand – the principle is similar to the

construction of a free-body diagram. But as any engineer who has gone
through a free-body analysis knows, the scope for errors is pretty high. In
other words, what we have is a process that is well understood and that can
immediately benefit from error-avoidance: a prime candidate for process-

Using This Section

The best way to read this section is to run over it thrice. First, pay attention
only to the logic – what we’re trying to do. Don’t try to remember the actual
options. Once you’re comfortable with the logic, carry out the steps yourself
using HyperMesh, using this section as a reference. Once you’ve done that,
scan this section again to ensure that what you understood is actually the
way it is. After you’ve done this, you’ll be ready to go on to the assignments!

Managing the CAE Process MBD Simulation with HyperWorks

The Process Itself

A sub-modeling process-template is shipped with HyperWorks, as a sample.

If you start HyperMesh and open the process template named

SubModeling.pmt, you’re guided through the already-defined process.
According to the definition programmed into this sample application, there
are 4 steps involved in sub-modeling, preceded by one additional step that’s
common to all Process Templates.

The first step, whenever you run a Process Template, is to choose whether
you want to restart from an earlier stopped-and-saved session or to start

If you choose a new session, the Process Tree starts from the first sub-
modeling step. (If you choose to restart a stopped-and-saved process, of
course, the process will resume from wherever it left off the earlier time.)
The tree-display shows how many steps are in the process, and also
indicates the current step by checking its box. Also, the familiar HyperMesh
interface has been replaced with a custom-made interface that tells you
exactly what to do – load a file. There’s even a default selection – door.hm.

The Process Manager Managing the CAE Process

If you select this file and click on the Load button, the process immediately
shifts to the next step.

Not only has the user-interface changed to reflect the next step in the
process, the tree has changed too – the green check-mark indicates that the
first step is complete and the second step is the one you’re working on.

By now the approach is pretty clear: the interface is tailored to suit the
specific task, recommended choices are offered to reduce the scope for
error, and you can track how far along the process you’ve gone.

Further, at any step in the process you can save your current state in case
you want to quite now and resume later.

This approach is consistent to all HWPM applications. A look at how this is

accomplished reveals the details behind the Process Template.

Managing the CAE Process MBD Simulation with HyperWorks

Behind The Scenes

Remember that multiple users or HyperMesh sessions can access the same
process template. Each time a user runs the template, a new instance is
created. The instance can be saved at any stage and restored at a later
session – the complete state of the application is saved along with the

Now let’s look at the code itself. To do this, we start the Process Studio and
open the same process template – SubModeling.pmt.

The window now opens the process definition. The Tools / Template
Preferences option defines the name for the process, and other options. The
tab-controls at the bottom of the window let us navigate between the code
and the interface. The Process tab is where you create the tasks that make
up the process-tree, while the Controls tab shows us any Java widgets used
in the application.

Each step in the process-tree has code associated with it. In the figure
above, the step named Import Model is associated with the file named
import_model.tcl. If you want to create a “collapsible” tree, like the
HyperStudy interface, set the Task Type to Folder.

Similarly, the Controls tab shows any Java widgets that the application uses.
Tk controls can be accessed directly from Tcl code, as illustrated by the
code. To complete our dissection, there’s one step left for us to understand
– where the Process Studio expects to find various files.

The Process Manager Managing the CAE Process

The Folder Structure

Depending on your design, your process can have any of up to 5
components: controls, help, icons, modules and tclincludes. For our sub-
modeling process the folder named modules contains 4 Tcl scripts, one for
each step in the process tree. The tclincludes folder contains scripts that
implement additional logic, if required. (There’s also a folder named models
that holds the HyperMesh files, but that’s specific to this process, rather than
being a feature of all process templates.)

Let’s look at the modules folder first. You can correlate these with the
process-layout. Each Tcl module is associated with a step in the process-
tree, and the order in which the tree is executed is defined by the layout:
the step named Import Model is associated with the script named

The file import_model.tcl contains 5 procedures, each of which is designed

to accomplish a specific step.

Note that each procedure in the file is named in a specific fashion – prefixed
with the string

proc ::hw::pmgr::${::hw::pmgr::namespace}::

This is the namespace that the HWPM engine sets up for the process. Each
Tcl file contains 4 predefined procedures, as well as others that may are
required by the logic. For instance, export_model.tcl and import_model.tcl
contain a callback function named OnBrowseFile( ), which is the function
that’s invoked when the user wants to choose a file or location.

The 4 essential procedures are

• DisplayWnd( ): this procedure is called by the HWPM engine to

create the window. Any setup for the display must be coded into
this module. In our example, the code first calls
GetDataFromDataModel( ), then creates widgets for this step.
Callbacks are created for widgets to process user-input. It then
returns to the HWPM Engine which waits for user input. If the user
clicks on a widget, its callback function is called. If the user wants
to go onto the next step in the process, the HWPM Engine calls
the procedure named Exec( ).

Managing the CAE Process MBD Simulation with HyperWorks

• GetDataFromDataModel( ): use this procedure to ask the HWPM

Engine what the current setting are, in case you want to
implement any logic based on these before control is passed over
to the user to choose an option. In our example, the path and
name of the default file (door.hm) is setup in this procedure. You
don’t have to code this procedure if you don’t want to since the
HWPM Engine never calls this procedure by itself. It’s up to you to
call this if you want to.

• Exec( ): this procedure is called by the HWPM engine when the

user wants to go on to the next step. In our example, the code
only checks to see whether a file has been selected or not. The
HWPM Engine goes on to the next procedure only if Exec( )
returns a value that’s not –1.

• SetDataInDataModel( ): If Exec( ) tells the HWPM Engine to

proceed, control passes to this function, where the programmer
can perform any post-data-input work. Once this procedure
returns control, the HWPM Engine goes on to the next step in the
Process Tree. Normally you would use this to save data that you
want to pass on to later steps in the process tree – persistent

Any supporting Tcl scripts you create should be stored in the folder
tclincludes. The folders controls, help and icons, of course, contain the
definitions of any widgets (JAR files, for Java applications), help text (HTML
files) or icons that your application uses.

While this sample application uses Tcl, remember that HWPM allows you to
use Java too – your application’s power is limited only by your imagination!

Most people find the concept of programming obvious, but the doing
Alan J. Perlis

Advanced Topics Managing the CAE Process

Advanced Topics
Don’t get fooled into thinking this chapter will make an expert out of you,
but do use this chapter to get going on multiple languages. The idea17 that
you should “learn at least a half dozen programming languages” is hard to
dispute, since one of your biggest design problems is to choose the mode of

It’s a good idea to read this chapter after you’ve worked on the assignments
that accompany this book. The only way to learn programming is to roll up
your sleeves and program!

Sir Maurice Wilkes18 observed

“As soon as we started programming, we found out to our surprise

that it wasn't as easy to get programs right as we had thought.
Debugging had to be discovered. I can remember the exact
instant when I realized that a large part of my life from then on
was going to be spent in finding mistakes in my own programs.”

Unless you know something Sir Maurice didn’t, there’s no getting away from
the fact that you should pay attention to and budget for the finding and
fixing of errors in your program. Errors can be of several forms – logical
errors, unforeseeable circumstances, syntactical errors, and so on.

The best way to get started is by starting small. Don’t write the entire
program and then start testing. Instead, remember that incremental-
development is a good way to go. Look at the functional design of your
application and decide at which points it makes sense to check if what
you’ve done so far is working as designed. (Unit testing is a standard
approach in eXtreme Programming).

A suggestion in Peter Norvig’s “Learn Programming in Ten Years”. The complete
article, at http://norvig.com/21-days.html, is strongly recommended reading.
Sir Maurice Vincent Wilkes is credited with several important developments in
computing, including the idea of symbolic labels, macros, and subroutine libraries.
Managing the CAE Process Advanced Topics

If you’re designing an application that has multiple components, don’t

assume that they will work as expected when combined just because they
work fine individually. Remember to establish tests for combinations.

If you find errors after the program’s done, as you inevitably will, use the
divide-and-rule approach. That is, separate the application’s functions into
those that are working and the one that isn’t. Then drill down into the code,
testing bits as you go.

Interactive debuggers are invaluable for compiled applications. In the

absence of an interactive debugger, generously print the values of variables
at various points so that you can track their values.

Debugging is partly art, partly science.

The scientific side is addressed by designing tests as rigorously as you

design the application itself. Design tests for success – that prove that the
application is doing what you wanted. Also design tests for failure – to check
how the application will behave when it encounters unexpected data, such
as wrong user-input.

The art, unfortunately, improves mainly with experience, but to sum up, the
steps you should try19 are:

• Reproducibility: try to discern a pattern of behavior so that

you can build possible cause-and-effect possibilities.

• Reduction: try to isolate the input that’s causing the bug. This
makes it easier to isolate the snippet of code that’s the root of
the problem.

• Deduction: test and eliminate the hypotheses formed thus far.

• Experimentation: check to see if the behavior recurs in

different scenarios.

• Experience: the more often you encounter a problem, the

more likely it is you have encountered probably causes.

Adapted from Terence Parr’s The Essentials of Debugging. See
Advanced Topics Managing the CAE Process

• Tenacity: don’t get discouraged if the process takes time.

Donald Knuth himself observed that “software is hard”.

Programming Languages – An Abstract View

There are some elements that are common to all programming languages.
Learning a new programming language becomes easier if you focus on
knowing just enough of one element, then going on to the next one. If we
remember that computer programs follow instructions and manipulate data,
then it becomes easier to follow the logical grouping.

Data Types
All data is stored in memory, whether in RAM or on other storage, in binary
form. Most programming languages, however, allow you to segregate data
into integers, floating point numbers, Boolean values, strings, etc. This
makes it easier for you to manipulate data consistently.

Strongly typed languages require you to declare the variable before using it.
That is, the variable’s name and its data type are specified before it is used
in the program to hold any data. Subsequent usage must match the rules for
the data type.

The language has to give you the ability to first store data in variables, then
to manipulate it. Assignment operators like = perform the first job, while
operators like + perform the latter.

Procedures and Functions

Modular programming makes it easier both to implement logic and to isolate
bugs. Whether they’re called procedures, functions or subroutines, the logic
is the same: the code must have an entry point, must be capable of taking
arguments, and must be capable of returning data to the calling function.

Most programming languages come with a predefined set of functions to

serve utility functions – for examples functions to calculate trigonometric
functions. Several languages allow you to use libraries to store, publish, and
access functions.

Two aspects that often confuse beginners are the concepts of scope and
visibility. When you define a variable in a module, the Operating System sets
Managing the CAE Process Advanced Topics

aside some storage for it. What should the Operating System do when the
module is complete? Should it retain it or release it? Some languages allow
you to decide this: variables that never go out of scope are called static
variables, while others are dynamic – they are released whenever the
module is done. If a variable has been released, it has gone out of scope,
which means your program can no longer access it.

In some languages, even if a variable is in-scope, it need not necessarily be

accessible to all modules. Variables that are accessible by all modules are
called Global variables. If variables in different modules have the same name
and are visible, the namespace is used to achieve scope resolution – that is,
to unambiguously specify which of these variables is being referred to.

Flow Control
Since programs need to take decisions, the programmer needs an ability to
set and test conditions, and proceed accordingly. The most common way to
do this is an if-then-else construct. First the if tests one or more
conditions. Depending on whether the condition is fulfilled or not, control
passes either to the then or to the else.

Do-loops are also common, allowing a set of instructions to be repeatedly

executed until a condition is either fulfilled (do-while) or violated (do-

Input and Output

From an input/output (I/O) perspective, there is a fundamental difference
between a user and a device. The former, interactive I/O, is unpredictable
while the latter can be assumed to follow a set of rules.

In today’s multi-tasking, GUI-driven operating systems, programs that

include interactive I/O must loop continuously, checking for user-input. As
we saw in the previous chapter, for Process Manager applications this loop is
executed by the HWPM engine. Once input is detected, the engine passes
control to a designated function, which is called a callback function.

File I/O, which is the most common device I/O, is easier. The program must
first open the device, then write to it or read from it, and close it when it’s
done. If a program exits or terminates without closing files, the Operating
System will usually close the file, but this is sloppy programming. It’s better
to ensure that all opening-and-closing of files is done explicitly by your code.

Advanced Topics Managing the CAE Process

Programming – The HyperWorks View

Tcl, as we have seen, is usually implemented as an interpreted language. A
Tcl interpreter is built into HyperWorks, so you need no additional software
to create or run Tcl scripts. You will usually store Tcl scripts in different files.
Since Tcl is interpreted, the entry point is the first function in the file that’s

Remember that Tcl has no data types – for Tcl, everything is a string of text.
It’s up to you, therefore, to anticipate what values a variable will hold and
proceed accordingly. This is particularly important if you access the
HyperMesh database from your code. Before we review the commonly used
HyperWorks functions provided by the Tcl API, we’ll look at some commonly
used “intrinsic” commands are listed here. (Use one of the references listed
at the end of this book for an introduction to Tcl itself.)

Remember that a hash-sign (“#”) is used for comments.

Common Tcl Commands

• set – to assign values to variables.

Example: set outputmessage “Command Failed”
assigns the data “Command Failed” to the variable named

• open – to open a file.

Example: open “datafile” r opens the file named
datafile for read-only access, while open “datafile” w
opens it for read-write access. If you use set filehandle
[open “datafile” r] you can use close when you’re
done with the datafile.

• Close – to close a file.

Example: If the handle of an open file is in the variable
filehandle, use close $filehandle to close the file.

• puts – to send output to a file or to the screen.

Example: puts “Command Failed” writes “Command
Failed”. If the string has been assigned to a variable

Managing the CAE Process Advanced Topics

named outputmessage, you would use puts “The

contents of outputmessage are $outputmessage”. If
the handle of an open file is in the variable filehandle, use
puts $filehandle $outputmessage to write to the file.

• gets – to get a line from a file.

Example: if the file-handle is stored in the variable
filehandle, you can use gets $filehandle line1 to read
the first line characters from the file and store it in the
variable line1. gets returns –1 if the end of the file is

• read – to get data from a file that’s already been opened.

Example: if the file-handle is stored in the variable
filehandle, you can use set line1 [read $filehandle
80] to read the first 80 characters from the file and store
these in the variable line1.

• exec – to execute an operating system command.

Example: use exec dir to list the contents of the current

• expr – evaluate a command.

Example: expr acos(-1) returns π.

• exit: to end the application.

Example: exit –1 returns the value –1 to the calling
application, if there is one. It’s up to the calling function to
use the returned value.

• file: to work with file attributes.

Example: file exists nameoffile returns –1 if the file
doesn’t exist. file mkdir dirname creates a folder
named dirname.

• proc – to define a procedure

Example: A procedure can optionally take arguments, and
usually returns a value to the caller. proc
nameofprocedure {argument1 argument2} { } defines
a procedure named nameofprocedure that takes 2

Advanced Topics Managing the CAE Process

Since Tk is inbuilt into Tcl, you can build widgets by including Tk commands
in your code. You should definitely review how to use the Tk commands
button and message. Commands like menu and menubar are also useful to
build slick interfaces quickly.

Common HyperWorks API Functions

The HyperWorks API provides a wide range of functions. You will need to
browse through the list, of course, as you work on building code. Some
commonly used API commands are listed here. Remember that we
encountered “* commands” such as *createbutton when we discussed
macros. When such commands are used in Tcl, the brackets should be
replaced by spaces. For instance, the command to create a fillet is

*createfillet( lineid1, lineid2, radius, trim-option,


when used in a macro, but is

*createfillet lineid1 lineid2 radius trim-option


when used in a Tcl script. Commands that start with hm are functions that
are provided by the HyperWorks API.

• hm_allentitiesinfo: to get information on all entities

Example: hm_allentitiesinfo assemblies returns a list
of all the assemblies in the database. The list is a string of
characters that the calling script can parse.

• hm_answernext: to force a yes / no reply for the next prompt

Example: *answer( ) cannot be used in Tcl scripts, so
this function is provided.

• hm_blockmessages: to turn off or on the display of messages

Example: use *hm_blockmessages 1 to turn off the
display of messages in the message-bar, and
*hmblockmessages 1 to turn them on again.

• hm_errormessage: to display a message

Example: use *hm_errormessage “Command Failed” 10
to display the text “Command Failed” on the message bar
and wait 10 seconds before removing the message.

Managing the CAE Process Advanced Topics

• hm_completemenuoperation: to clean up
Example: when working with HyperMesh, the graphics
area is cleaned up after the menu is complete. When
using Tcl, you may need to issue this command explicitly.

• hm_count: to count the number of entities of a given type

Example: hm_count nodes returns the number of nodes
in the database.

• hm_entityincollector: to count the entities in a collector

Example: hm_entityincollector comp 1 nodes returns
the number of nodes in the component collector whose id
is 1.

• hm_entitymaxid: to get the largest label used for an entity type

Example: hm_entitymaxid nodes returns the largest id
used for nodes.

• hm_getcollectorname: to get the name of a collector, given the id

Example: hm_getcollectorname comp 1 returns the
name of the component collector whose id is 1.

• hm_getcompthickness: to get the thickness of a component

Example: hm_getcompthickness 1 returns the thickness
assigned to the collector whose id is 1.

• hm_getentityvalue: to get specific information about an entity

Example: hm_getentityvalue NODES $nodeId "x" 0
returns the x coordinate of the node whose id is in the
variable nodeId.

• hm_nodevalue: to get the coordinates of a node

Example: hm_nodevalue $nodeId returns the x, y and z
coordinates of the node whose id is in the variable nodeId.

• hm_nodelist: to get the list of nodes connected to an element

Example: hm_nodelist $elemId returns the ids of all
nodes connected to the element whose id is in the variable

• hm_getfloat: to get a floating point number from the user

Advanced Topics Managing the CAE Process

Example: set tolerance [hm_getfloat “Tolerance”

“Enter value”] displays the caption “Tolerance”, issues
the prompt “Enter Value” and stores the entered value in
the variable tolerance.

• hm_getint: to get an integer from the user

Example: set nodeId [hm_getint “Node Selection”
“Enter id”] displays the caption “Node Selection”,
issues the prompt “Enter id” and stores the entered value
in the variable nodeId.

• hm_getstring: to get a text string from the user

Example: set compName [hm_getint “Component Name”
“Enter name”] displays the caption “Component Name”,
issues the prompt “Enter name” and stores the entered
value in the variable compName.

• hm_getfilename: to get a filename from the user

Example: set fileName [hm_getfilename “File Name”
“Enter name”] displays the caption “File Name”, issues
the prompt “Enter name” and stores the entered value in
the variable fileName.

• hm_info: to get information regarding the HyperWorks installation

Example: hm_info ALTAIR_HOME returns the folder in
which HyperWorks is installed. You can get the working
directory, the path where the executables reside, the
names of the executables, the name of the application the
script is running in, the name of the current collector, the
name of the currently running macro, etc.

In addition to the API itself, there are 4 variables that HyperWorks


::g_ConversionPrecision – the number of significant digits to which all

floating point numbers returned by Tcl API functions will be rounded off

::g_hw_argc – the number of arguments passed by HyperWorks to the

current script

::g_hw_argv – the list of arguments passed by HyperWorks to the current

Managing the CAE Process Advanced Topics

::g_hw_version – the version number of HyperWorks

An Annotated Example
To put all this in proper context, let’s look at a real, working program. This
example is a script to import all IGES files in a given folder into HyperMesh.
The lines in blue are the actual code, while comments are in italics and are
indented for clarity.
# Display a message to the user, who can only
click on “OK”.
tk_messageBox -title "Directions" -message "Pick a
source directory. All IGES files \n in that directory
will be imported." -type ok
# Display a Dialogue Box from which the user can
select the file. Note that the code does not
allow for the user clicking on “cancel”. The
name of the chosen file is stored in the
variable fileSource
set fileSource [tk_chooseDirectory -mustexist true -
title "Find Files In"]
# Define the variable named “format”, which
we’ll use to build the filenames.
set format {#iges\\iges}

# Generate the file list. Remember that Unix is

case sensitive, while Windows is not. Note how
the loop is constructed. We search for files
with the suffix igs or iges
foreach fileName [glob –nocomplain

# Extract File Name Information

set temp1 [file tail $fileName]

# Break the name at the “.”

set temp2 [split $temp1 .]
# We’ll use the filename to organize the
data on import
set compName [lindex $temp2 0]
if {$fileName != ""}
# Set the state of the all
component collectors: display of
elements is off, display of
geometry is on
*displaycollectorwithfilter components
"none" "" 0 1

Advanced Topics Managing the CAE Process
# Create a component collector
with the name that’s given by the
variable compName_surfs, and
assign it a mat collector id = 1,
and set the color to 1.
*collectorcreate components
"$compName\_surfs" "1" 1
# Create a component collector
with the name that’s given by the
variable compName_lines, and
assign it a mat collector id = 2,
and set the color to 1.
*collectorcreate components
"$compName\_lines" "2" 1
# Create a component collector
with the name that’s given by the
variable compName_points, and
assign it a mat collector id = 3,
and set the color to 1.
*collectorcreate components
"$compName\_points" "3" 1
# Run the Iges translator (we
defined the variable named
“format” above). We do not want to
overwrite any existing entities
and use an automatic cleanup
*feinput "$format" "$fileName" 0 0 -1 1 0

# Now that the geometry’s

imported, move the surfaces,
points and lines to the
corresponding collectors (we
created them just before the
*clearmark surfaces 1
*createmark surfaces 1 "displayed"
*movemark surfaces 1 "$compName\_surfs"

*clearmark lines 1
*createmark lines 1 "displayed"
*movemark lines 1 "$compName\_lines"

*clearmark points 1
*createmark points 1 "displayed"
*movemark points 1 "$compName\_points"
# Clean up: if there were no
surfaces / lines / points, the
corresponding collector would be
*EntityDeleteEmpty components 1

Managing the CAE Process Advanced Topics
# Now that the import-and-organization is
over, wind up by setting the color …
*autocolor components
# … and set the display-state of all
component collectors – elements off,
geometry on
*displaycollectorwithfilter components "all" "" 0 1

You could, of course, use ::hwat::io::LoadFilesFromDir to achieve the

same affect with less code. Note that this function is a part of the
HyperWorks Automation Toolkit function.

The APIs provided to the TCL modules is much smaller than the APIs
provided for Java, largely because the Java development-paradigm allows
the development of a wider range of applications than Tcl. Of course, Tcl
applications can use

::hw::pmgr::PmgrExecuteJavaScript $id $strJavaCmd nSuccess

to do anything that the Java Beans can do.

The Java APIs support Swing (the JFC), and come with a set of libraries and
beans that your application can use. If you’re using a Java IDE (such as
Eclipse), you should add hwmutils.jar, hmsuite.jar, hwmetaphase.jar, and
dbbeans.jar and all the jar files in the lib folder (the path depends on your
installation - C:\Altair\hw8.0sr1\javaapps\WIN32\pmgr\lib for example) to
the set of required libraries.

The supplied controls are in 3 classes – utility controls, database controls

and HyperMesh specific controls. When you use the Process Studio to lay
out the user-interface, the bindings decide the order in which the controls
are called at run-time.

All the APIs provided by the Process Manager FrameWork are encapsulated
in the interface IHWMFrameWork. To access the framework, beans should
implement a class named com.altair.hwm.interfaces.IHWMControl. If it
does, when the bean is instantiated, the Process Manager passes the
IHWMFrameWork instance to the SetFrameWork method (note that the bean’s
constructor does not have access to the FrameWork). Beans that don’t
implement this class don’t receive the FrameWork handle, but can do their
own work, of course.

Advanced Topics Managing the CAE Process

Among other facilities, the FrameWork provides access to

• a data model for beans to store and share data, using

IHWMDataModel. The DataModel is persistent – that is, it is saved
with the process instance, so you can retrieve data from it when the
process is restarted in a subsequent session.

• inter-process communications (such as connections to an RDBMS

using JDBC and SQL, interfaces to other applications using sockets,
connections to servers using SOAP, etc.) using IHWMCommMgr

• the Workflow – that is, the set of tasks that make up the process-
tree – using IHWMWorkFlow

• the menus using IHWMMenuToolbarCustomizer

The package com.altair.hwm.beans.utils (in hwmutils.jar) contains

several ready-made beans that implement the FrameWork and are
consistent with the HyperWorks GUI. This means you should, as far as
possible, use these as base classes, rather than using Swing components

All in all, unless you have prior experience with Java or an object-oriented
language like C++, you should look at Tcl as a preferred customization

Finally, remember that the API is for Java, not JavaScript - while Java and
JavaScript share several vocabulary and syntax constructions, the languages
are intended for very different purposes.

HyperWorks uses XML to interface MotionSolve with MotionView, for
instance. XML provides several advantages to the programmer. You probably
will not need to decipher the structure used by HyperWorks, but it’s
interesting anyhow to understand the how and why of XML.

Like other markup languages, XML uses tags liberally. But unlike HTML,
which almost everyone who uses a computer has encountered, XML only
defines the content, not the appearance. This is extremely significant since it
allows for separation between form and data. The developer, therefore, has
tremendous freedom. Unlike HTML, where the tags supported by the

Managing the CAE Process Advanced Topics

language are predefined, XML allows you to define your own tags.
Remember that XML files are intended to be read by applications, not by
humans. Since the XML file contains the tags you’ve defined, its easy to
write an application to read the XML file. The XML “code” tells the
application what the data means.

A Document Object Model, that helps process the contents using

relationships between objects in the hierarchy, can represent the structure
inherent in the XML file.

Computers are useless. They can only give you answers.

Pablo Picasso

Glossary and References Managing the CAE Process

Glossary And References

API Application Programming Interface. A set of subroutines that can be
used by programmers to access specific functions of the host
application or operating system.

Applet An application-let, related to an application just as a piglet is related

to a pig, is a software component that runs within another program
such as a web browser. While it can be run independently, it’s
designed to have such a narrow focus that there's little point in
running it by itself. From a programming perspective, an applet does
not have a main( ). Instead, init( ), start( ) and stop( ) are the normal
entry points.

Application A program that is designed to work all-by-itself, as opposed to a

subroutine or function.

Callback Event-driven programming is an approach in which the application

waits for events. That is, the program loops continuously, checking for
an event such as a mouse-click. Callback functions help implement this
approach – each event that the programmer is prepared to respond to
is assigned a callback function. This is the function that is executed
when that event is detected.

Command Line Specifications or data supplied to an application when it’s being

started. For instance, HyperMesh can be started with a variety of
command line arguments – see the online documentation for details.

Compiler An application that converts source code into an executable program

(strictly speaking, compilers generate object code, which is then
converted to an executable application by a “linker”).
One of the advantages of this approach is that the original program is
protected – others cannot reconstruct the approaches used in the
original program.

Constructor An essential component of object-oriented programming, the

constructor is a function that is called whenever an item is created by
the program. It’s usually used to set initial values.

Controls Elements of a GUI (Graphical User Interface) that the user can interact
with to trigger an event that the application will respond to. In
window-based programs, these are often referred to as widgets.

Database Broadly speaking, a database is a set of data that can be retried as

desired. By that definition, a HM file itself is a database, for example.
More commonly, though, the term refers to relational databases.

Managing the CAE Process Glossary and References

Decompiler An application that converts compiled code back to source code.

DLL Dynamic Link Library – a set of functions that can be called by an


Function See subroutine

Instance Most computers can run multiple applications – this means the same
application may well be invoked several times. For example, you can
start HyperMesh more than once on the same computer – you will
then be running several “sessions” or “instances” of HyperMesh.

Interpreted An application that is used to execute source code. Any programming

language can be either interpreted or compiled, in theory. An
interpreted implementation usually executes more slowly than a
compiled implementation. TCL, for example, is usually interpreted, but
can be compiled to protect the source code.

JAR A JAR file is a Java Archive that’s a container for other Java
components. It’s a platform-independent file format that combines
many files – such as Java applets and their components - into one. It’s
a convenient way of packaging together class files, associated images,
and other data files. A JAR file can be decompiled.

Makefile Often multiple files are used to store different elements of an

application – functions, images, etc. These are then compiled to create
an executable. If one of the elements changes, the executable should
be recompiled – a makefile is widely used to ensure that this happens.

Namespace In plain English, a namespace is a context. In programming, it is used

to provide a unique identification. For instance, you can only use the
same filename for two files if they are in different folders. Just
specifying the filename would not be enough since it’s impossible to
know which file is being referred to. If the folder name is used along
with the filename, then it’s quite clear. In this case, the folder name is
the “namespace”.

SOAP Short for either Simple Object Access Protocol or Service Oriented
Architecture Protocol, is a method for applications to exchange
messages across networks – a client sends a request to a server,
which replies. Reliant on XML, SOAP is one of several middleware
products. CORBA is another commonly used method to achieve the
same function.

Socket A mechanism that allows programs to communicate, either on the

same machine or across a network. Every computer on a network is
identified by its network address. In addition, every computer has a
number of ports. A program that wants to receive a connection from
other programs asks the operating system (using an API) to create a
socket and associate this with a specific port. It then monitors this
Glossary and References Managing the CAE Process
socket and associate this with a specific port. It then monitors this
socket, waiting for input. Other programs send data or messages to
the network address and port number – this data is picked up by the
listener, which responds appropriately.

Source Code A set of instructions that is easily readable by a human. Usually,

source-code is written in a language like TCL, C or Fortran.

Spawn Used in the context of programming, a “spawned” application is

started by another application program, instead of being started by
the user.

SQL Structured Query Language – a language used by many commercial

relational database programs.

Subroutine A program that is designed to be called by other programs, rather

than working independently. Similar to (and sometimes, depending on
the programming language, the same as functions), they are often
packaged in DLLs.

Swing A Java Foundation class designed for GUIs. Controls derived from
Swing are platform-independent and inherit their look-and-feel from
the Operating System.

Widget Window-based gadget. Also see controls.

XML Extensible Markup Language

Tutorials, FAQs, Documentation, References and more.

Java decompiler – useful if you want to examine Java files (jars)

A decompiler plug-in for Eclipse

An Integrated Development Environment (IDE) for Java.

All you could ever want to know about TCL.

Managing the CAE Process Glossary and References

Other Resources
www.altair-india.com/edu, which is periodically updated, contains case
studies of actual usage. It also carries tips on software usage.

Macros on the User Page

The syntax for *createbutton is:

*createbutton(page, name, row, column, width, color, help,

macro, [arg1, …]

• Page indicates which menu page the button will appear on. The
value must be between 1 and 5
• Name is the text displayed on the button
• Row determines which row the button is placed on. Rows start from
0 at the bottom of the screen. The maximum value depends on the
resolution of your display
• Column determines which row the button is placed on. The value
must be between 1 and 10
• Width must be less than 10
• Color can be any of RED, BLUE, GREEN, CYAN, MAGENTA and
BUTTON. The color must be entered in upper-case
• Help is the text displayed on the menu bar when the button is
• Macro is the name of the macro (defined by
*beginmacro(macroname) ) that’s called when the button is clicked.
• Arg1, arg2 etc. are optional – if present, they are passed on to the
macro as arguments.

Templex and Templates

Templex is principally used for two things. First, to translate text data (such
as Finite Element models) to and from HyperMesh. Second, to create
mathematical expressions.

A template is a text file that defines the form of the output or input file using
a series of commands. HyperMesh uses the template to determine how to
read from or write to the output or input file. Text processing consists of 5

• before( ): this block is executed once for each data type

Glossary and References Managing the CAE Process

• beforecollector( ): commands in this block are executed once for

each collector

• format( ): these commands are processed for each entity in the


• aftercollector( ): commands in this block are executed once for each

collector, after completing all the data in the collector

• after( ): similar to the before( ) block, these commands are

executed once for each data type

If you want to write a HyperMesh file out in the form

1 8 16 24 32 40
NODE 1 0.0 0.0 0.0
NODE 2 8.0 0.0 0.0
NODE id x y z

the template file should be:

*nodes( )
*before( )
*string("NODE DATA")
*end( )
*format( )
*string("NODE ")
*field(integer, id, 8)
*field(real, x, 8)
*field(real, y, 8)
*field(real, z, 8)
*end( )
*string("END NODES")
*end( )
*output( )

The words preceded with asterisks are Template commands, and the
variables within the brackets (id, x, etc.) are data names. The complete set
of commands and names is listed in the online documentation.
Managing the CAE Process Glossary and References

Mathematical expressions can be embedded in the commands. If, for

instance, you want to offset every node by 100 in the x direction, use

*field( real, [x+100.0],8)

The interpreter reads the contents of the square brackets as a formula and
evaluates it accordingly. Operators can implement pretty complicated logic.
Not only do they include commands such as test-for-equality (==, !=, <, >,
<=, >= ) and logical expressions ( &&, || ), you can also use conditions such
*if and *loopif as to determine execution-branches.

Formulae can also be constructed from Template Functions, which allow you
to query the data in the database. For instance, you can use @count( ) to
count the number of nodes in the database. Template functions are
preceded by the symbol @ and must be enclosed in square brackets. A
complete list is in the on line documentation. Some useful functions are:

• @cos( ), @sin( ), @tan( ) where the angle is in radians

• @acos( ), @asin( ) and @atan( ) for inverse trigonometric functions

(the values are returned in radians)

• @atan2( ) to get the inverse tangent of x/y (the results is in radians)

• @entitymaxid( ) to get the largest id in use for a particular type of


• @log( ) and @log10( ) for the natural logarithm / log-base-10

• y
@pow( ) and @exp( ) for x and e

• @checkfile( ) to check if a file exists

• @count( ) and @entitiycollector( ) to count the number of

entities in the database and in a collector respectively

• @sqrt( )and @fabs( ) and for the square-root and absolute value

• @stringequal( ) and @stringinstring( ) for lexical functions