This is a showcase review for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.
Mechanical engineering software has hit a crossroads: traditional problem-oriented code is clashing with more modern, object-oriented languages, causing debugging problems and incompatible skill sets among CAD/CAM developers.
Smart Manufacturing Technology (SMT) is attacking the problem by switching its applications to C# for greater speed, better compatibility, and easier maintenance. A key tool in the conversion process is ANTS Profiler, Red Gate’s automated .NET profiler that helps the company optimize its code.
SMT offers a range of technologies for automotive and off-road vehicle manufacturers, focusing on transmission, axle and driveline components. The company’s main target is the rapidly changing Chinese market.
“In China there is considerable drive for improvement but in short timescales,” says Owen Harris, SMT’s senior analysis consultant. “We provide hardware, consulting services and software analysis tools that enable our clients to rapidly improve design, development and manufacturing.”
Preventing product failure
SMT’s PC-based, mechanical engineering software combines elements of computer-aided design (CAD) for defining components and assemblies with computer-aided engineering (CAE) for analyzing manufacturability and performance, optimizing design, and reporting results. The company specializes in designing and manufacturing gears – a key component in any traditional transmission or axle system.
“Although gears have been in use since the dawn of the industrial revolution, there are still many issues surrounding their correct design and manufacturing,” Harris says.
Software for design and engineering analysis needs to ensure that gears can survive at least 100,000 miles of driving. Badly designed or manufactured gears can cause noise and mechanical failure. Bending and compressive stresses due to poor engineering can lead to gear tooth breakage and pitting.
“The calculations required to design and analyze gears involve a large number of specialist inputs using detailed algebra, iteration and repeated evaluation of trig metric functions,” Harris says. “Code clarity and quality are of the highest importance due to the technical nature of the product.”
Best of both languages
Previously, SMT used a mix of old-style, mathematically strong Fortran for number crunching at the backend, and more modern, development languages such as Visual Basic for front-end applications.
“This leads to difficult debugging and a code base that’s not understood by all the developers,” Harris says. “It also requires a lot of extra work to get the data from one language to the other, depending on where the language split occurs.”
Fortran is efficient at solving engineering or scientific problems, but can be abstract for systems-level work. Alternately, C++ is powerful and flexible in dealing with the hardware/software interface, but somewhat complex; objects and their associated operations must be identified, for example, and all necessary classes and subclasses must be constructed.
Harris and his team believe they found the best of both worlds in C#.
“We wished to avoid a common mistake of attempting to micro-optimize small sections of the code as it was being written and compromising code clarity in the process,” Harris says. “As C# offers good performance, is highly productive and well supported, it was sensible to use it exclusively.”
Clean programming saves time
The first program being written in C# is SMT’s new spur-helical gear design and manufacturing application. Once completed, it will be used to design new gears and troubleshoot existing designs for manufacturing and performance problems.
The program, now in the final stages of testing before release, is written entirely in C# with only a few function calls to a Fortran math library. The graphical user interface is standard .NET, except for the charts, which were created with a program called Nevron Chart, and the 3D graphics, which were produced with the free OpenGL wrapper Tao and the free HTMLEdit program.
Security is achieved using a Hasp hardware dongle, and user file load/save is done using custom-created XML; this allows Harris and his team to keep a close eye on what’s written and maintain file compatibility with future versions. Databases used by the program (containing lists of bearings, materials, and so on) were written using .NET serialization, then encrypted using the dongle. This makes hacking the program difficult, and keeps competitors from reading the database files.
“All classes must have well-understood roles, and all functions must be short and have a well-defined purpose,” Harris says.
Once the program was written, Harris used ANTS Profiler to identify slow lines of code. ANTS Profiler’s summary document revealed functions hidden in C# code that were taking too long to run. The following piece of code, for example, uses a profile of two-dimensional points (X,Y) to create a drawing. The profile is symmetrical about the X-axis, so the drawing is created in two loops: joining a line between each point, and joining a line between each point in reverse order with the point mirrored about the X-axis.
Polyline polyline = new Polyline();
foreach(Vector2D vec in Profile)
for(int i = Profile.Count - 1; i >= 0; i--)
polyline.Points.Add(new Vector2D(Profile[i].X, Profile[i].Y/-2));
ANTS revealed that the value of the property “Profile” was derived from other properties in the application. Those other properties had to be accessed each of the four times Profile was called per iteration – twice in a row for the second loop alone, as indicated in the last line of code above. While the calculated value was always the same, that process of calling it up took lots of time.
Once the problem was identified, the solution was simple: store the Profile property value in a local variable at the start of the function:
Vector2D  storedProfile = Profile;
Polyline polyline = new Polyline();
foreach(Vector2D vec in storedProfile)
for(int i = storedProfile.Count - 1; i >= 0; i--)
polyline.Points.Add(new Vector2D(storedProfile [i].X, storedProfile [i].Y/-2));
The issue was identified and solved within about 10 minutes – resulting in a 100 percent performance improvement for that piece of code.
Harris estimates that the overall switch to C# for the GUI and analysis code makes the new application three times faster than if his team had stuck with separate languages.
“Virtual prototyping and design optimization require many repeated calculations,” Harris says. “Even with the ever-increasing desktop computing power available, speed of calculation is still very much an issue.”
Further information about ANTS Profiler is available at the Red Gate website (http://www.red-gate.com/). Here you will find reviews and testimonials, as well as an online demonstration, walk-through and a fully-functional, free trial.