Description
The way is proposed to connect to the software in C# and library of integration universal program system of finite-element analysis in the field of automatic engineering calculations ANSYS offered.
Developing own software or using integration?
The problems of integration of own programs with others increasingly cover the area of the software development. Many programmers believe that one has to write his own application, that integration with others' developments is not good, while they do not take into account the size of the developers' teams, their experience and expediency. Although it is possible to implement the same calculation system using finite elements method, but it will not be of high quality. Is it possible to repeat the way of the project development, that took 10-20 years? Of course it is impossible and often is just impractical.
But the problem of integrating own programs with powerful computing systems and the transfer of the results from one to another is much more in demand. We have powerful computing packages, the development and debugging of which took many years, we have a certain task that is hard to implement in one computing system or we lack necessary capabilities that we can implement ourselves.
With the beginning of the integration of all software products in the ANSYS company under the unified ANSYSWorkbench environment, the possibility to integrate the programs directly with this environment appeared. The architecture of ANSYSWorkbench is based on using Java and Visual Basic scripts (VB), by means of which the initiation of these or that ANSYS modules, that are called applets, takes place.
The very first option that comes to mind of any developer is that it sufficient to initiate from the program the scripts for Java-Script, written or generated earlier. However, this method has one rather serious flaw: each time when you call the script it will be necessary to re-open Workbench, to initialize applet ANSYS, and only then send commands to the core calculation. This is evident from the script, which is located at:
C: \ Program Files \ ANSYS Inc \ v110 \ AISOL \ SDK \ samples \ JPDL \ Demo.js.
Script text below [3]:
oWB = new ActiveXObject("AnsysWB.WB.90");
oWB.StartApplet = "AAOApplet";
oWB.Run();
oWB.Title = "ANSYS Workbench";
ConnectToAnsysCS();
varfs, a;
ForAppending = 8;
fs = new ActiveXObject("Scripting.FileSystemObject");
a = fs.CreateTextFile("d:\\rundir\\testfile.txt", true);
with (ansys.cmd) {
for (l = 4; l < 10; l++) {
_clear();
_prep7();
_view(null, -1, -2, -3);
// var l=4;
var w = 3;
var d = 2;
// block(null,4,null,3,null,2);
block(null, l, null, w, null, d);
kp4x = ansys.apdl.get("KP", 4, "LOC", "X");
commentx = "KP 4 X LOC = ";
commentx += kp4x;
kp4y = ansys.apdl.get("KP", 4, "LOC", "Y");
commenty = "KP 4 Y LOC = ";
commenty += kp4y;
kp4z = ansys.apdl.get("KP", 4, "LOC", "Z");
commentz = "KP 4 Z LOC = ";
commentz += kp4z;
ret = _com(commentx);
ret = _com(commenty);
ret = _com(commentz);
this.a.WriteLine(commentx);
this.a.WriteLine(commenty);
this.a.WriteLine(commentz);
sphere(1);
vsbv(1, 2);
et(2, 92);
vmesh("all");
da(9, "all");
sfa(4, 1, "pres", 10000000);
mp("EX ", 1, 27E+06);
mp("PRXY", 1, 0.3);
finish();
_solu();
solve();
finish();
_post1();
set("LAST");
plnsol("S", "EQV");
_replot();
finish();
}
}
a.Close();
Responsible part for loading the Workbench environment
If you generate the script programmatically and run it, it will be very inconvenient, because the script will be executed by the external processor, which will greatly complicate its debugging. Besides, generating a script that is responsible for a full work cycle is very inconvenient. The main problem was getting and saving a descriptor for WorkBench environment.
From this point of view, the most interesting part is the one responsible for loading of the WorkBench environment:
oWB = new ActiveXObject("AnsysWB.WB.90");
oWB.StartApplet = "AAOApplet";
oWB.Run();
oWB.Title="ANSYS Workbench";
Motivation
While studying this and other scripts, I had a question: if Java-Script can do it, why C# can not? It turned out, that C# can do it quite well. During the installation of ANSYS the software development studio Microsoft Visual Studio 2010 finds links to all ANSYS libraries, but they are very “shortened". But among them there was a library that was responsible for the program work with the Work Bench environment: AnsysWB, which connects to ANSYSWBLib namespace.
To run ANSYS it is enough to write the following code:
ANSYSWBLib.WBClass wb = new ANSYSWBLib.WBClass();
wb.CommandLine.Directory = @"c:\tmp\";
wb.CommandLine.JobName = "asdf";
wb.CommandLine.CadFile = @"c:\tmp\qwe.ewq";
wb.StartApplet = "AAOApplet";
wb.Run(0);
So this code allows you to run ANSYS, and as a starting applet the classic ANSYS applet will be indicated directly, and it will be launched. But further we have to organize the transfer of control commands to it and this is where difficulties arise. In Java-Script it is implemented with the following line
App.Script.ans_sendcommand(Command)
Where “App” - the reference to the module of descriptor AAOApplet. It is stored in the class:
wb.AppletList.get_WBApplet("AAOApplet").Applet.App
.NET FrameWork helped me
But in the 11th version of ANSYS in the linked libraries I did not find the interface for work with ANSYS applet. Fortunately, .NET FrameWork has a library like Microsoft.JScript that allows you to compile JavaScript scripts directly in the memory and execute them, while the necessary function can be initiated from C#.
For this purpose I decided to write my class that would realize all the necessary opportunities to work with ANSYS/Class code, which is presented below
class WBCommand
{
ANSYSWBLib.WBClass wb;
public WBCommand(ANSYSWBLib.WBClass WB)
{
wb = WB;
aao=wb.AppletList.get_WBApplet("AAOApplet").Applet.App;
string code = @"function closure()
{
return function (App, Command)
{
returnApp.Script.ans_sendcommand(Command);
}
}
closure()";
//
SendCommandClosure = (Closure)Microsoft.JScript.Eval.JScriptEvaluate(code, Microsoft.JScript.Vsa.VsaEngine.CreateEngine());
}
private Closure SendCommandClosure = null;
private Closure SetWorkingDirectoryClosure = null;
private object aao = null;
public object SendCommand(string Command)
{
returnSendCommandClosure.Invoke(null, new object[] { aao, Command });
}
public void SetWorkingDirectory(string WorkingDirectory)
{
SendCommand("/CWD, " + WorkingDirectory);
}
}
During initiation of the constructor of my class the formation of the initiated procedure in JavaScript and saving of its entry points take place.
string code = @"function closure()
{
return function (App, Command)
{
returnApp.Script.ans_sendcommand(Command);
}
}
closure()";
//
SendCommandClosure=(Closure)Microsoft.JScript.Eval.JScriptEvaluate(code,Microsoft.JScript.Vsa.VsaEngine.CreateEngine());
For the initiation of the procedure, this method was implemented
public object SendCommand(string Command)
{
returnSendCommandClosure.Invoke(null, new object[] { aao, Command });
}
As the input parameter that must have a text command, during the initiation of the Java Script function the link to the applet, which was received in the constructor and saved in the aao variable, is additionally transferred.
Now, while initiating the SendCommand method it will be possible to transfer the ANSYS commands in APDL language from our external application, completing all the necessary actions. This method emulates the input of the commands directly into the ANSYS command line, but after all many commands need confirmation. In order to avoid the requests for confirming the actions it is sufficient not to insert the commands one by one, but rather write them in APDL file and initiate a
SendCommand("/inp,f,apdl") command. In this case, ANSYS will not require confirmation to execute this or that operation.
Conclusion
If necessary, one can conduct a parametric optimization of the model for the accordance of the modeling results in the group of real testing with their computational models. It is also compounded by the fact that each software product computes in its own way and the results of the computations in ANSYS will not be identical to computations in ABAQUS with the similar parameters of the model given. It depends on the specific implementation of the calculations, types of the finite elements and even the location of grid nodes.
As a result, an engineer inputs the material parameters, not even knowing how precisely they correspond to the reality. Moreover, the variability of optimal parameters can reach 70% of the test results, especially since the processing of tests is performed in the framework of one or maximum two terms of strength, often the simplest, and for complex models we do not always even know how to determine the required parameters, especially when they are offered on the basis of the experience in certain range.
To address this problem the task to integrate the program with an ANSYS estimated core has been defined. The task of integration was successfully completed, but not without problems. And the main problem was the complete lack of documentation in the public domain, so I think the information on the implementation of the integration will be very useful for those who have the same objective, but lack information.
Комментариев нет:
Отправить комментарий