From CAELinuxWiki
Revision as of 22:58, 7 September 2009 by Projectionist (Talk | contribs) (Doing the study)

Jump to: navigation, search

Doing an automated study with Salome and CodeAster

This example may seem a little artificial. However this was part of my work this summer for a research partner of my university. I am not allowed to place the original problem here because conflicts with the companies secrets would be inevitable. So I have to construct a new problem around the expertise I gained from my task. Even if you do not have a similar task you may learn something.


If there is the need to analyze lots of topological likewise geometries then automation cam make life easier. This paragraph describes automatable analysis of a 2D part section. Given the case the geometry comes as list of vertices in a known order we can read this list with a script and create a TUI script.

The input data

The input data for the analysis is stored in a text file containing information about the geometry and the load. The geometry, a 2D part section, is given by a list of vertices. The point where the concentrated load acts on the structure is also given. Distributed load in 3D results in concentrated load in the 2D section. The text file may come from a CAD program. At least in my work this was the case.

# data for part sect01

name = 'sect01'

case1.fx = 120.0;
case1.fy = 21.5;

case2.fx = -54.0;
case2.fy = 97.2;

vrtcs = [
12.0 100.0
... ...
... ...

Processing the input data

We process the data file with a python script. This script generated the TUI script which will be processed by Salome. We could also directly import the geometry in the TUI script via exchange file format but then we would not know where to apply the load and where to constrain the degrees of freedom. At least I would not know.

Doing the study

Here is where all the magic happens. Don't get confused with all the boxes, this source code belongs to one file. However these boxes subdividing the code into blocks may improve readability.

   #!/usr/bin/env python
   # Perform a FE analysis using Salome and CodeAster
   # G. Holzinger, JKU Linz, 2009
   # The text file containing the geometry data must reside in the same directory as this file.
   # Provide the filename as argument!
   # If the filename contains dots ('.') then the file must have a file extension (i.e. sect01.txt or sect01.v02.txt)
   # Files without file extension are also allowed (i.e. sect01)
   # Not allowed are files with filenames containing dots but without file extension (i.e. sect01.v02) for 
   # everything left of the rightmost dot excluding this dot is used as projectname and is used to build 
   # the file paths too. This would not work in this case!
   import os
   import sys
   from subprocess import *
   def usage():
   	print "\tusage: ./ FILENAME"
   	print ""
   	print "\texample: ./ sect01.txt"
   # retrieve number of arguments
   nargs = len(sys.argv)
   # no argument was passed
   # nargs == 1 because the filename of the file itself is automatically passed as argument
   if nargs == 1:
   	print "no arguments passed!"
   # one argument was passed
   if nargs == 2:
   	argument = sys.argv[1]
   	# remove file extension
   	index = sys.argv[1].rfind(".")
   	if index == -1:
   		name = sys.argv[1]
   		name = sys.argv[1][0:index]
   	print name
   	# initialize status variables
   	sts0 = (0, 1)
   	sts1 = (0, 1)
   	sts2 = (0, 1)
   	sts3 = (0, 1)
   	sts4 = (0, 1)
   	sts5 = (0, 1)
   	# create TUI script for salome
   	print "calling: ./ " + argument
   	p0 = Popen("./ " + argument, shell=True)
   	sts0 = os.waitpid(, 0)
   	if sts0[1] == 0:
   		# create mesh
   		p1 = Popen("source /SALOME-ROOT/salome_5.1.2/KERNEL_5.1.2/", shell=True)
   		sts1 = os.waitpid(, 0)
   		p2 = Popen("/SALOME-ROOT/salome_5.1.2/KERNEL_5.1.2/bin/salome/runSalome -t -u ./", shell=True)
   		sts2 = os.waitpid(, 0)
   		if sts2[1] == 0:
   			# create finite element study
   			p3 = Popen("./ " + argument, shell=True)
   			sts3 = os.waitpid(, 0)
   			if sts3[1] == 0:
   				# create the export file
   				p4 = Popen("./ " + name, shell=True)
   				sts4 = os.waitpid(, 0)
   				# run the study	
   				exportFullPath = os.getcwd() + ("/" + name)*2 + ".export"
   				resuFullPath = os.getcwd() + ("/" + name)*2 + ".resu"
   				p5 = Popen("/opt/SALOME-MECA-2009.1-GPL/aster/outils/as_run --run " + exportFullPath, shell=True)
   				sts5 = os.waitpid(, 0)
   				if sts5[1] == 0:
   					# show results
   					p6 = Popen("cat " + resuFullPath, shell=True)
   					sts6 = os.waitpid(, 0)
   				# end if
   			# end if
   		# end if
   	# end if
   	# print status report
   	print "return values of called scripts and programs\n\n"
   	print " " + str(sts0)
   	if sts0[1] == 0:
   		print "\tOk\n"
   		print "\tFailed\n"
   	print " " + str(sts1)
   	if sts1[1] == 0:
   		print "\tOk\n"
   		print "\tFailed\n"
   	print "runSalome: " + str(sts2)
   	if sts2[1] == 0:
   		print "\tOk\n"
   		print "\tFailed\n"
   	print " " + str(sts3)
   	if sts3[1] == 0:
   		print "\tOk\n"
   		print "\tFailed\n"
   	print " " + str(sts4)
   	if sts4[1] == 0:
   		print "\tOk\n"
   		print "\tFailed\n"
   	print "as_run: " + str(sts5)
   	if sts5[1] == 0:
   		print "\tOk\n"
   		print "\tFailed\n"
   if nargs > 2:
   	print "too many arguments passed!"

to be continued ...