473,321 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Cobyla help needed

2
Hi there guys

I am an engineering student using python to try and optimize an Abaqus FEA simulation and am having problems using the cobyla, basically I havn't a clue. I was wondering could someone illustrate the many problems with the script below?

Cheers
Dan

import numpy
import os
import scipy.optimize.cobyla
import string

def minimise_mass(mass):
os.system("abq661 cae script=bottlesim2ndstep.py") # Function
myfile=open('totalbottle', 'r')
totalbottle = myfile.readline()
print "Total Bottle",totalbottle,"g"

#myfile=open('topload', 'r')
#topload = myfile.readline()
#print "Topload", topload

myfile=open('mainbody', 'r')
mainbody = myfile.readline()
print "Mainbody",mainbody,"mm"

myfile=open('lid', 'r')
lid = myfile.readline()
print "Lid",lid,"mm"

return totalbottle

def constraint_topload(thickness):
myfile=open('topload', 'r')
topload = myfile.readline()
print "Topload",topload,"N"
return topload-200 # constraint saying topload >=200

def constraint_thickness(thickness):
return thickness-2 # constraint saying thickness >=2

thickness=5 # initial guess for thickness
x_opt=scipy.optimize.fmin_cobyla(minimise_mass, thickness, [constraint_topload,
constraint_thickness], consargs=None, rhobeg=1.0, rhoend=1e-10, iprint=1,
maxfun=1000000)
print "optimised thickness", x_opt
#print x
#print y
Mar 12 '08 #1
2 2365
jlm699
314 100+
In the future you should try to use [ code ] tags to make your code more readable

Ok so, when you do your readline ops, Python pulls in the end of line operator as well.
Basically your problem is that topload, totlebottle, lid, etc... all these values are in string form, and have a line separator attached (ie, instead of lid = 5 you have lid = '5\n'). Cobyla is expecting numbers, so:

A simple fix would be to simply do the following:
Expand|Select|Wrap|Line Numbers
  1. totalbottle = int(myfile.readline())
  2. # ORRR
  3. totalbottle = float(myfile.readline())
  4. # Depending on what the possible values are, which I'm assuming you'll want float
To further ensure you don't have the new line characters you can do this:
Expand|Select|Wrap|Line Numbers
  1. totalbottle = myfile.readline().strip()
  2. # This will strip off the '\n' but leave your totalbottle value as a string
  3. # So in order to use cobyla with this valueyou'll still need to convert to float or int
  4. totalbottle = float(myfile.readline().strip())
  5. # this last one is redundant, since float() will ignore the white space character (\n) anyway
  6.  
After simply adding the float() conversion and making up random values for the text files I got the following:
Expand|Select|Wrap|Line Numbers
  1. C:\DOCUME~1\ADMINI~1\Desktop\PYTHTE~1>python cobyla.py
  2. Total Bottle 540 g
  3. Mainbody 15 mm
  4. Lid 20 mm
  5. ...
  6. # Doesn't change
  7. ...
  8. Topload 300 N
  9. Total Bottle 540 g
  10. Mainbody 15 mm
  11. Lid 20 mm
  12. Topload 300 N
  13. Total Bottle 540 g
  14. Mainbody 15 mm
  15. Lid 20 mm
  16. Topload 300 N
  17.  
  18.    Normal return from subroutine COBYLA
  19.  
  20.    NFVALS =   13   F = 5.400000E+02    MAXCV = 0.000000E+00
  21.    X = 5.000000E+00
  22. optimised thickness 5.0
  23.  
  24. C:\DOCUME~1\ADMINI~1\Desktop\PYTHTE~1>
Mar 12 '08 #2
pyhton
2
jlm669

Thanks for the reply was very helpful

Daniel
Mar 14 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: System | last post by:
Hello All, Redhat 9.0 Mysql 3.23.56 ==> Running I want to upgarde to 4.0.13 but this is the error it says: # rpm -Uvh MySQL-server-4.0.13-0.i386.rpm warning: MySQL-server-4.0.13-0.i386.rpm: V3...
8
by: Stephen | last post by:
I am trying to add some code to below to include a datatable and fill the datatable. The reason for doing this is so as I can check to see whether there are any rows returned by the stored...
13
by: Joe Feldman | last post by:
This position is located in the South Bay Area in Northern California. If you are interested please send me your resume in a word .doc so that I can review it. If this does not look like a match,...
0
by: Cindy B | last post by:
Please send your resume and position to Cindy@AtlanticResource.com! I CAN NOT accept candidates that ARE OUTSIDE OF THE US! NO PHONE CALLS PLEASE! Email your resume to me! Position:SQL...
3
by: Wade | last post by:
I would like to install the .Net 1.1 framework on a Web Server running W2K to be able to run ASP.NET files, but I'm not sure where to find the files I need for the .Net framework. I have ".NET...
5
by: Steve | last post by:
Hi, I am sitting down to design our next set of internal apps. I would like to approach this in a way that would allow me to break logical parts of the application that handle specific tasks...
0
by: ultradiv | last post by:
I have a VB.NET application partly built that produces an xml output (just a file at present) I have a .NET webserver and SQLserver 2000 I need to be able to send the xml to the webserver/database...
28
by: Ian Davies | last post by:
Hello I would appreciate some help from someone who has knowledge of working with css, php javascript and how they interact. Ive been working on a task for the last few days and have started to...
37
by: C_guy | last post by:
Does anyone know of a (hopefully free) tool that can traverse a project and determine which "#include"s are not needed or needed in every .C file? This would be helpful in removing header...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.