ymk02-papadopoulos-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/matlab-ansys-v02… ·...

39
________________________________________________________________________________________ ________________________________________________________________________________________ 1 Υπολογιστικές Μέθοδοι στις Κατασκευές 8 ο εξάμηνο ΠΑΡΑΔΟΣΗ με e-mail: Ημέρα 24/06/14, (11:59μμ) Η παράδοση γίνεται στέλνοντας e-mail στο [email protected] . Κάθε email έχει τίτλο (λατινικοί χαρακτήρες, κεφαλαία): YMK01-EPITHETO-AM-DEADLINE πχ. YMK02-PAPADOPOULOS-02111066-27.03.13 Στο κείμενο του e-mail σας γράφετε συνοπτικά την εργασία σας ενώ συνημμένα έχετε τα αρχεία όσα ζητούνται. Παρακαλώ MHN συμπιέζετε τα αρχεία (zip/rar format). ΑΣΚΗΣΗ: Βελτιστοποίηση μέσω Matlab-Batch Δίνεται το παρακάτω έλασμα με διαστάσεις που φαίνονται στο σχέδιο και πάχος 2mm, το οποίο θα αναλυθεί με το λογισμικό ANSYS. Για το έλασμα δίδεται ότι είναι κατασκευασμένο από υλικό PMMA (plexiglass) μέτρου ελαστικότητας Ε = 2500 MPa, λόγου Poisson ν = 0.375 και πυκνότητας ρ = 0.00118 gr/mm 3 . Το κίτρινο τμήμα (διαστάσεων 15x25x2 mm) είναι πακτωμένο. Κρεμάμε στην μπλε περιοχή με τα ημικυκλία (Φ2 mm) μάζα 250 gr (πίεση 0.052336748 MPa). Η μέγιστη επιτρεπόμενη τάση von Misses δίνεται σ max = 67.2887 MPa. Για τη μελέτη του ελάσματος να επιλεχθεί ως πεπερασμένο στοιχείο το Solid187. ΕΘΝΙΚΟ ΜΕΤΣΟΒΙΟ ΠΟΛΥΤΕΧΝΕΙΟ ΣΧΟΛΗ ΜΗΧΑΝΟΛΟΓΩΝ ΜΗΧΑΝΙΚΩΝ Τομέας Μηχανολογικών Κατασκευών και Αυτομάτου Ελέγχου Λεωνίδας Αλεξόπουλος, Λέκτορας Κτήριο (Ε), 3ος όροφος, τηλ: 772-1666 Email: [email protected] Προσωπική ιστοσελίδα: http://users.ntua.gr/leo/

Upload: others

Post on 02-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 1

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

ΠΑΡΑΔΟΣΗ με e-mail: Ημέρα 24/06/14, (11:59μμ)

Η παράδοση γίνεται στέλνοντας e-mail στο [email protected] . Κάθε email έχει τίτλο (λατινικοί χαρακτήρες, κεφαλαία):

YMK01-EPITHETO-AM-DEADLINE πχ.

YMK02-PAPADOPOULOS-02111066-27.03.13

Στο κείμενο του e-mail σας γράφετε συνοπτικά την εργασία σας ενώ συνημμένα έχετε τα αρχεία όσα ζητούνται. Παρακαλώ MHN συμπιέζετε τα αρχεία (zip/rar format).

ΑΣΚΗΣΗ: Βελτιστοποίηση μέσω Matlab-Batch Δίνεται το παρακάτω έλασμα με διαστάσεις που φαίνονται στο σχέδιο και πάχος 2mm, το οποίο θα

αναλυθεί με το λογισμικό ANSYS. Για το έλασμα δίδεται ότι είναι κατασκευασμένο από υλικό PMMA

(plexiglass) μέτρου ελαστικότητας Ε = 2500 MPa, λόγου Poisson ν = 0.375 και πυκνότητας ρ = 0.00118

gr/mm3. Το κίτρινο τμήμα (διαστάσεων 15x25x2 mm) είναι πακτωμένο. Κρεμάμε στην μπλε περιοχή με τα

ημικυκλία (Φ2 mm) μάζα 250 gr (πίεση 0.052336748 MPa). Η μέγιστη επιτρεπόμενη τάση von Misses

δίνεται σmax = 67.2887 MPa. Για τη μελέτη του ελάσματος να επιλεχθεί ως πεπερασμένο στοιχείο το

Solid187.

ΕΘΝΙΚΟ ΜΕΤΣΟΒΙΟ ΠΟΛΥΤΕΧΝΕΙΟ ΣΧΟΛΗ ΜΗΧΑΝΟΛΟΓΩΝ ΜΗΧΑΝΙΚΩΝ Τομέας Μηχανολογικών Κατασκευών και Αυτομάτου Ελέγχου Λεωνίδας Αλεξόπουλος, Λέκτορας Κτήριο (Ε), 3ος όροφος, τηλ: 772-1666 Email: [email protected] Προσωπική ιστοσελίδα: http://users.ntua.gr/leo/

Page 2: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 2

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Σκοπός της άσκησης είναι η ελαχιστοποίηση του βάρους του ελάσματος με ταυτόχρονη μείωση του βέλους

κάμψης. Για να γίνει αυτό θα πρέπει να αφαιρεθεί τμήμα MONO της κόκκινης περιοχής (διαστάσεων

100x25x2 mm) με αφαίρεση οποιοδήποτε σχήματος είναι επιθυμητό. Βασική προϋπόθεση είναι να μην

υπερβαίνεται η μέγιστη επιτρεπόμενη τάση von Misses. Ως κύρια απαίτηση της άσκησης είναι η μείωση του

βάρους του αρχικού τεμαχίου, με όριο όμως το μέγιστο επιτρεπόμενο βέλος κάμψης να μην υπερβαίνει τα

40 mm. Για κάθε 1 mm βέλους κάμψης μεγαλύτερο των 40 mm αφαιρούνται 1.5 μονάδες (στην κλίμακα

του 10).

Η ελαχιστοποίηση του βάρους θα γίνει τρέχοντας το ANSYS με Batch μέσω του MATLAB. Η αρχική

γεωμετρία δίνεται στο παράρτημα Δ. Παίρνετε όλες τις γραμμές κώδικα που βρίσκονται εκεί και τις

αντιγράφετε σε ένα αρχείο .txt με όνομα της επιλογής σας. Στη συνέχεια ανοίγετε το ANSYS και επιλέγετε

το αρχείο που δημιουργήσατε από το menu: File’Read Input From’ και έχετε την αρχική γεωμετρία.

Ζητούνται:

1. Η μάζα του υλικού που έμεινε μετά τη βελτιστοποίηση (στο Body Text).

2. Το μέγιστο βέλος κάμψης που προκύπτει μετά τη βελτιστοποίηση (στο Body Text).

3. Η μέγιστη τάση von Misses που αντιστοιχεί στην τελική γεωμετρία (στο Body Text).

4. Ο κώδικας Matlab στο Body Text αλλά KAI σε αρχείο .m επισυνημμένο.

5. Η τελική γεωμετρία σε format .SLDPRT από το SW (βλ. Παράρτημα Γ - Οδηγίες SolidWorks)

επισυνημμένη.

ΠΑΡΑΡΤΗΜΑ Α - Οδηγίες για το Matlab-Batch:

1. Φτιάχνετε την αρχική γεωμετρία με την ανωτέρω διαδικασία.

2. Κατασκευάζετε τον όγκο που πρόκειται να αφαιρεθεί και τον αφαιρείτε (μπορεί να έχει όποιο

3. παραμετροποιημένο σχήμα κρίνετε εσείς αποδοτικότερο). Μπορείτε να διαμορφώνετε:

(a) είτε απευθείας το .log file

(b) είτε ένα ή περισσότερα βοηθητικό/α αρχείο/α που μπορείτε να δημιουργήσετε και να

τροποποιείτε

(c) είτε προγραμματίζοντας απευθείας σε APDL (βλ. Παράρτημα Ε – ANSYS Parametric Design

Language Guide)

Page 3: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 3

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Αν επιλέξετε τον (b) τρόπο η εισαγωγή αρχείου στον κώδικα γίνεται με την εντολή:

/Input,’filename’,’extension’, ‘directory’, , 0 . Θα πρέπει να παραμετροποιήσετε το .log file έτσι

ώστε να δέχεται ως είσοδο ό,τι υπάρχει στα βοηθητικά αρχεία.

4. Επιλέγετε Π.Σ. και εισάγετε τα Material Properties.

5. Φτιάχνετε πλέγμα.

6. Βάζετε πακτώσεις και φορτία.

7. Λύνετε το πρόβλημα.

8. Εμφανίζετε τα αποτελέσματα που ενδιαφέρουν την άσκηση (τα βλέπετε τουλάχιστον μια φορά από

το menu list results), έτσι ώστε να εμφανίζονται στο .out αρχείο του Batch.

9. Έξοδος και αποθήκευση όλων.

10. Πριν τρέξετε το Batch πηγαίνετε στο menu Options και κάνετε untick την επιλογή “Save Existing

Output Files From Batch Runs”.

11. Συνίσταται να τρέχετε το Batch σε ξεχωριστό directory από αυτό που βρίσκεται το .log file

12. Τρέχετε πρώτη φορά το Batch χειροκίνητα.

13. Φτιάχνετε κώδικα της επιλογής σας στο Matlab, ο οποίος τρέχει το Batch και βελτιστοποιεί το

πρόβλημα σας. (βλ. Παράρτημα Β - Χρήσιμες εντολές MATLAB).

14. Την τελική μορφή την εισάγετε στο SolidWorks και παράγετε το αρχείο .SLDPRT (βλ. Παράρτημα Γ -

Οδηγίες SolidWorks).

ΠΑΡΑΡΤΗΜΑ Β - Χρήσιμες Εντολές MATLAB

Παρακάτω, παρουσιάζονται ορισμένες χρήσιμες εντολές της Matlab που μπορείτε να λάβετε υπόψη κατά

την υλοποίηση του προγράμματος βελτιστοποίησής σας.

fileID=fopen(‘directory\file_name.extension’,’permission’)

Ανοίγει το επιθυμητό αρχείο με την άδεια που δίνει ο χρήστης.

Permissions:

feof(fileID)

Ελέγχει αν το αρχείο έφτασε στο τέλος του. Αν το αρχείο έφτασε στο τέλος επιστρέφει την τιμή 1

αλλιώς επιστρέφει 0.

fgets(fileID)

Διαβάζει την επόμενη γραμμή του αρχείου.

‘ r ’ Open file for reading

‘ w’ Open or create a file for writing. Discard existing

contents, if any.

‘ a’ Open or create new file for writing. Append data

to the end of the file.

‘ r+’ Open file for reading and writing.

‘ w+’ Open or create new file for reading and writing.

Discard existing contents, if any.

‘ a+’ Open or create new file for reading and writing.

Append data to the end of the file.

Page 4: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 4

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

frewind(fileID)

Γυρίζει στην πρώτη γραμμή του αρχείου.

fprintf(fileID, formatSpec, A1, A2,…,An)

εκτυπώνει στο αρχείο το επιθυμητό περιεχόμενο και διαγράφει ότι υπήρχε μέσα πριν. Τα

formatSpecs «ενημερώνουν» την εντολή, για το τι είδος στοιχείου πρόκειται να γραφτεί στο αρχείο.

formatSpec:

fclose(fileID)

κλείνει το αρχείο που έχετε ανοίξει, του οποίου έχετε δώσει όνομα fileID κατά την κλήση της ρουτίνας

fopen.

ΠΑΡΑΡΤΗΜΑ Γ - Οδηγίες SolidWorks:

Το τελικό αρχείο που θα παραδώσετε (βλ. Ζητούμενα) θα πρέπει να περιέχει επισυνημμένη και την τελική

γεωμετρία σε SOLIDWORKS PART (προσοχή: όχι Drawing!). To παράρτημα αυτό αναφέρεται στις οδηγίες

εξαγωγής της τελικής γεωμετρίας σε μορφή SLDPRT.

1. Ανοίγετε το ANSYS και από το menu: File Read Input From ανοίγετε το .log file που προέκυψε

μετά τη βελτιστοποίηση.

2. Από το menu: FileExport κάνετε εξαγωγή της τελικής γεωμετρίας σε μορφή IGES σε όποιο φάκελο

θέλετε. Το όνομα του αρχείου θα πρέπει να είναι της μορφής onoma-epitheto.iges.

3. Από το SolidWorks κάνετε open το αρχείο που δημιουργήσατε.

4. Προσέξτε η κλίμακα που εμφανίζεται στο αρχείο SW να συνάδει με αυτήν που έχετε ορίσει από το

ANSYS. Το ANSYS αποθηκεύει τις διαστάσεις σε units, τα οποία συνήθως μεταφράζονται στο SW σε

m. Αν σας εμφανιστεί κάτι τέτοιο, αλλάξτε τις διαστάσεις ώστε να δίνονται σε mm.

5. Χαράξτε σε μια επιφάνεια του τεμαχίου το ονοματεπώνυμο σας με λατινικούς χαρακτήρες (Βλ. 1ο

μάθημα SolidWorks).

6. FileSave as onoma-epitheto.SLDPRT

Value Type Type in format spec

Integer, signed %d or %i

Integer, unsigned %u

Floating point number %f

Exponential notation, i.e. 3.14e+00 %e

Single character %c

String of characters %s

Page 5: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 5

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

ΠΑΡΑΡΤΗΜΑ Δ – APDL αρχικής γεωμετρίας

/BATCH /COM,ANSYS RELEASE 15.0 UP20131014 21:33:31 05/20/2014 /input,menust,tmp,'' /GRA,POWER /GST,ON /PLO,INFO,3 /GRO,CURL,ON /CPLANE,1 /REPLOT,RESIZE WPSTYLE,,,,,,,,0 /REPLOT,RESIZE /PREP7 BLC4,0,-12.5,15,25,2 BLC4,0,-2.5,10,5,2 VSBV, 1, 2 CYL4,10,0,2.5,90,0,-90,2 VSBV, 3, 1 BLC4,15,-12.5,100,25,2 BLC4,115,-12.5,2,25,2 BLC4,117,-12.5,3,25,2 FLST,2,4,6,ORDE,2 FITEM,2,1 FITEM,2,-4 VADD,P51X CYL4,116,-12.5,1,0,0,180,2 CYL4,116,12.5,1,180,0,360,2 FLST,3,2,6,ORDE,2 FITEM,3,1 FITEM,3,-2 VSBV, 5,P51X SAVE FINISH ! /EXIT,ALL

Page 6: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 6

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

ΠΑΡΑΡΤΗΜΑ Ε – ANSYS Parametric Design Language Guide

Το αρχείο αυτό αναφέρεται σε έναν εναλλακτικό τρόπο για να υλοποιήσετε την βελτιστοποίηση (βλ. Παράρτημα Α – Οδηγίες για το Matlab – Batch, τρόπος (c)).

ANSYS Parametric Design Language Guide

A quick reference

Page 7: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 7

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

ANSYS Parametric Design Language Guide

Introduction to APDL APDL stands for ANSYS Parametric Design Language, a scripting language that you can use to

automate common tasks or even build your model in terms of parameters (variables). While all ANSYS commands can be used as part of the scripting language, the APDL commands are the true scripting commands and encompass a wide range of other features such as repeating a command, macros, if-then-else branching, do-loops, and scalar, vector and matrix operations.

Using Parameters

Parameters are APDL variables. You don’t need to explicitly declare the parameter type. All numeric values (whether integer or real) are stored as double-precision values. Parameters that are used but not defined1 are assigned a near-zero value of approximately 2-100. Parameter types

ANSYS uses two types of parameters: scalar and array. Character strings (up to eight characters long) can be assigned to parameters by simply enclosing the string in single quotes. APDL also provides several types of array parameters: numeric, character, string and table (a special numeric type that automatically interpolates values). Guidelines for parameter names Parameter names must:

Begin with a letter

Contain only letters, numbers and underscore characters

Contain no more than 32 characters Valid Invalid ABC_ 2COA (begins with a number) RI3 M&&A (invalid character “&”) When naming parameters

Avoid parameter names that match commonly used ANSYS labels

Parameter names ARG1 through ARG9 and AR10 through AR99 are reserved for local parameters. Generally local parameters are used in macros. Use of these names as “regular” parameters is not recommended.

Listing Parameters

Once you have defined parameters, you can list them using the *STATUS command. If *STATUS command is issued without arguments, it provides a list of all the currently defined parameters. For example:

1 See also:

Preventing substitution of numeric parametric values.

Page 8: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 8

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

*STATUS

You can also check the status of individual parameters by providing these as arguments to the

*STATUS command. The following example shows the status of the PI parameter. *STATUS, PI

Hiding Parameters from the *STATUS

You can use a parameter naming convention to “hide” parameters from the *STATUS command. Any parameters whose name ends in a underscore (_) will not be listed by *STATUS.

Page 9: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 9

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Defining Parameters

1. Assigning parameter values during execution You can use the *SET command to define parameters. For example:

*SET, AB, -22 *SET, PI, 3.14 *SET, LC, ‘LOADCASE’ You can use an “=” as a shorthand way of calling the *SET command (this is the most convenient method). For example: AB = -22 PI = 3.14 LC = ‘LOADCASE’

2. Assigning parameter values at startup You can define parameters as arguments when launching ANSYS from the operating system command

line. Simply type parameter definitions after the ANSYS execution command (which is system dependent) using the format –Name Value. For example, ansys140 –param1 80.2 param2 -0.1

It is a good practice to avoid assigning one or two character parameter names at startup to avoid conflicts with ANSYS command line options.

3. Assigning ANSYS-Supplied Values to parameters ANSYS provides two powerful methods to retrieving values:

The *GET command, which retrieves a value from a specified item and stores it in a specified parameter.

The in-line get functions, which can be used in operations. Each get function returns a specific value from a specific item.

Using the *GET command

The *GET command retrieves an ANSYS-supplied value for an item (a node, an element, an area, etc.) and stores it as a user-named parameter. Various keyword, label, and number combinations identify the retrieved item. For example, *GET,A,ELEM,5,CENT,X returns the centroid x-location of element 5 and stores the result as parameter A. The format for get function is: *GET,Par,Entity,ENTNUM,Item1,IT1NUM,Item2,IT2NUM where • Par is the name of the parameter to store the retrieved item. • Entity is a keyword for the item to be stored. Valid keywords are NODE, ELEM, KP, LINE, AREA, VOLU, etc. For a complete list of valid keywords, see the *GET description in the Command Reference. • ENTNUM is the number of the entity (or zero for all entities). • Item1 is the name of an item for a particular entity. For example, if Entity is ELEM, Item1 will be either NUM (the highest or lowest element number in the selected set) or COUNT (the number of elements in the set).

Page 10: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 10

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Using In-line Get functions

For some items, you can use in-line "get functions" in place of the*GET command. A get function returns a value for an item and uses it directly in the current operation. This process allows you to bypass the dual steps of storing the value with a parameter name and then entering the parameter name in an operation.

Get function arguments can themselves be parameters or other get functions. For instance, get function NELEM(ENUM,NPOS) returns the node number in position NPOS for element ENUM. Combining functions NX(NELEM(ENUM,NPOS)) returns the x-location of that node.

Get Function Summary summarizes the available get functions.

4. Get parameters from external files The PARRES command reads parameters from a coded file. The parameters read may replace or change

the current parameter set. The format for PARRES command is: PARRES, Lab, Fname, Ext, -- where Lab

Read operation: NEW --

Replace current parameter set with these parameters (default). CHANGE --

Extend current parameter set with these parameters, replacing any that already exist. Fname

File name and directory path (248 characters maximum, including the characters needed for the directory path). An unspecified directory path defaults to the working directory; in this case, you can use all 248 characters for the file name. The file name defaults to Jobname.

Ext Filename extension (eight-character maximum). The extension defaults to PARM if Fname is blank.

-- Unused field.

Note (Alternatively we could use /INPUT or *USE commands)

Page 11: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 11

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Deleting Parameters You can delete specific parameters in two ways:

Issue the "=" command, leaving the right-hand side of the command blank. For example, to delete the QR parameter issue this command: QR=

Issue the *SET command (Utility Menu> Parameters> Scalar Parameters), but don't specify a value for the parameter. For example, to delete the QR parameter via the *SET command issue the command as follows: *SET,QR,

Using Character Parameters Typically, character parameters are used to provide file names and extensions. For example, a

desired file name can be assigned to a character parameter, and that parameter can be used anywhere a file name is required.

Parametric expressions Parametric expressions involve operations among parameters and numbers such as addition,

subtraction, multiplication, and division. For example: X=A+B The following is a complete list of APDL operators:

Operator Operation

+ Addition

- Subtraction

* Multiplication

/ Division

** Exponentiation

< Less-Than Comparison

> Greater-Than Comparison

You can also use parentheses for clarity and for "nesting" of operations, as shown above. The order in which the ANSYS program evaluates an expression is as follows: 1. Operations in parentheses (innermost first) 2. Exponentiation (in order, from right to left) 3. Multiplication and division (in order, from left to right) 4. Unary association (such as +A or -A) 5. Addition and subtraction (in order, from left to right) 6. Logical evaluation (in order, from left to right)

Parametric Functions

A parametric function is a programmed sequence of mathematical operations which returns a single value, such as SIN(X), SQRT(B), and LOG(13.2). The following table provides a complete list of functions currently available in ANSYS.

Page 12: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 12

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Saving and Writing Parameters

To write parameters to a file, use the PARSAV command. The format for PARSAV command is: PARSAV, Lab, Fname, Ext, -- where

Lab Write operation: SCALAR --

Write only scalar parameters (default). ALL --

Write scalar and array parameters. Parameters may be numeric or alphanumeric. Fname

File name and directory path (248 characters maximum, including the characters needed for the directory path). An unspecified directory path defaults to the working directory; in this case, you can use all 248 characters for the file name. The file name defaults to Jobname.

Ext

Page 13: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 13

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Filename extension (eight-character maximum). The extension defaults to PARM if Fname is blank.

-- Unused field.

If you wish, you can write up to ten parameters or array parameters using FORTRAN real formats to

a file. You can use this feature to write your own output file for use in other programs, reports, etc. To do this, use the *VWRITE command The format for *VWRITE command is: *VWRITE, Par1, Par2, Par3, Par4, Par5, Par6, Par7, Par8, Par9, Par10, Par11,Par12, Par13, Par14, Par15, Par16, Par17, Par18, Par19

Data items (Par1, Par2, etc.) may be array parameters, scalar parameters, character parameters

(scalar or array), or constants. You must evaluate expressions and functions in the data item fields before using the*VWRITE command, since initially they will be evaluated to a constant and remain constant throughout the operation. You can also use the *MWRITE command to write data to a specified file (writes a matrix to a file in a formatted sequence).

The format descriptors can be in either Fortran or C format. You must enclose Fortran format descriptors in parentheses. They must immediately follow the*VWRITE command on a separate line of the same input file. Do not include the word FORMAT. For example: *vwrite,real_float_number (‘real_float_number = ', F20.10) The F descriptor takes the syntax Fw.d where w

Is the width of the data field in characters. d

Is the number of digits to the right of the decimal point.

Page 14: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 14

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Writing Data Files Generally, we use the following commands for writing data to files. *cfopen,param1 *vwrite,param1 (‘param1 = ',F20.10) *vwrite,param2 . . *cfclos *CFOPEN command opens a “command” file. The format for *CFOPEN command is: *CFOPEN, Fname, Ext, --, Loc

Where

Fname File name and directory path (248 characters maximum, including the characters needed for the directory path). An unspecified directory path defaults to the working directory; in this case, you can use all 248 characters for the file name. The file name defaults to Jobname.

Ext Filename extension (eight-character maximum). The extension defaults to CMD if Fname is blank.

-- Unused field.

Loc Determines whether existing file will be overwritten or appended: (blank) -- The existing file will be overwritten. APPEND -- The file will be appended to the existing file.

*CFCLOS command closes a “command” file. (There are not arguments to this command)

Page 15: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 15

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

APDL as a Macro Language

You can record a frequently used sequence of ANSYS commands in a macro file (these are sometimes called command files). Creating a macro enables you to, in effect, create your own custom ANSYS command. For example, calculating power loss due to eddy currents in a magnetic analysis would require a series of ANSYS commands in the postprocessor. By recording this set of commands in a macro, you have a new, single command that executes all of the commands required for that calculation.

In addition to executing a series of ANSYS commands, a macro can call GUI functions or pass values into arguments.

You can also nest macros. That is, one macro can call a second macro, the second macro can call a third macro, and so on. The following is a very simple example of a macro file. !this is a commentwith ‘!’ we start a comment from this point to the end of the line /post1 esel,all !select all items etable,valume,volu !store volume in element table ssum !sum element table elements *get,total_volume,ssum,,item,volume !total_volume = sum of ‘volume’ finish

If this macro was called mymacro.mac, you could execute this sequence of commands with the following single ANSYS command2 *use, mymacro, Creating a macro You can create macros either within ANSYS itself or using your text editor of choice. If your macro is fairly simple and short, creating it in ANSYS can be very convenient.

2 See also /INPUT command

Page 16: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 16

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

If you are creating a longer, more complex macro or editing an existing macro then you will need a text editor. Also, using a text editor allows you to use a similar macro or ANSYS log file as the source for your macro.

You can use your favorite text editor to create or edit macro files. Any ASCII editor will work. Moreover, ANSYS macros can have their lines terminated by either UNIX or Windows line ending conventions (carriage-return, line-feed pairs or simply line-feeds) so you can create a macro on one platform and use it on several platforms.

For any long, complex macro you should always consider either using a similar macro as a starting point or running the task interactively in ANSYS and using the resulting log file as the basis of your macro3. Macro file Naming Conventions

Macros are a sequence of ANSYS commands stored in a file. Macros should not have the same name as an existing ANSYS command, or start with the first four characters of an ANSYS command, because ANSYS will execute the internal command instead of the macro. The following naming restrictions apply to macro files:

The file name cannot exceed 32 characters.

The file name cannot begin with a numeral.

The file extension cannot contain more than eight characters (if you are executing the macro as if it were an ANSYS command it should have the extension .mac.)

The file name or extension cannot contain spaces.

The file name or extension cannot contain any characters prohibited by your file system and for portability should not contain any characters prohibited by either UNIX or Windows file systems.

Macro Search Path

By default, ANSYS searches for a user macro file (.mac extension) in the following locations: 1. The /ansys_inc/v140/ansys/apdl directory. 2. The directory (or directories) designated by the ANSYS_MACROLIB environment variable (if defined) or the login (home) directory. This environment variable is documented in The ANSYS Environment chapter of the Operations Guide. 3. The directory designated by the $HOME environment variable. 4. The working directory.

You can place macros for your personal use in your home directory. Macros that should be available across your site should be placed in the /ansys_inc/v140/ansys/apdl directory or some commonly accessible directory that everyone can reference through the ANSYS_MACROLIB environment variable.

3 See also *CREATE, *CFWRITE, /TEE commands

Page 17: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 17

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Using Macro Library Files

As a convenience, ANSYS allows you to place a set of macros in a single file, called a macro library file.

Macros libraries have no explicit file extension and follow the same file naming conventions as macro files. A macro library file has the following structure:

MACRONAME1 . . . /EOF MACRONAME2 . . . /EOF MACRONAME3 . . . ./EOF For example, the following macro file contains two simple macros: mybloc /prep7 /view,,-1,-2,-3 block,,4,,3,,2 finish /EOF mysphere /prep7 /view,,-1,-2,-3 sphere,1 finish /EOF Note that each macro is prefaced with a macro name (sometimes referred to as a data block name) and ends with a /EOF command. Executing Macros and Macro Libraries

You can execute any macro file by issuing the *USE command. For example, to execute the macro called MYMACRO (no extension) residing in the current working directory, you would issue *use,mymacro

In this case, the macro takes no arguments. If instead the macro was called MYMACRO.MACRO and resided in /myaccount/macros, you could call it with

Page 18: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 18

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

*use,/myaccount/macros/mymacro.macro

Note that the *USE command allows you to enter the path and extension along with the file name and that these are not entered as separate arguments.

If a macro has a .mac file extension and resides in the search path, you can execute it as if it were an ANSYS command by simply entering it in the command input window. For example, to call mymacro.mac you could simply enter Mymacro You can also execute macros with a .mac extension through the Utility Menu> Macro> Execute Macro menu item.

If the same macro takes arguments for more information about passing arguments to macros), then these can be entered on the command line as follows mymacro,4,3,2,1.5 or *use,mymacro.mac,4,3,2,1.5

Executing macros contained in macro libraries is similar. You must first specify the library file using the *ULIB command.

For example, to specify that macros are in the mymacros.mlib file, which resides in the /myaccount/macros directory, you would issue the following command: *ulib,mymacros,mlib,/myaccount/macros/

After selecting a macro library, you can execute any macro contained in the library by specifying it through the *USE command. As with macros contained in individual files, you can specify arguments as parameters in the *USE command. Local Variables

APDL provides two sets of specially named scalar parameters which are available for use as local variables. These consist of

A set of scalar parameters that provide a way of passing command line arguments to the macro. A set of scalar parameters that can be used within the macro. These provide a set of local variables

that can be used to define values only within that macro.

There are 19 scalar parameters that you can use to pass arguments from the macro execution command line to the macro. These scalar parameters can be reused with multiple macros; that is, their values are local to each macro. The parameters are named ARG1 through AR19 and they can be used for any of the following items: • Numbers • Alphanumeric character strings (up to 32 characters enclosed in single quotes)

Page 19: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 19

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

• Numeric or character parameters • Parametric expressions Local Variables Within Macros

Each macro can have up to 80 scalar parameters used as local variables (AR20 through AR99). These parameters are completely local to the macro, and multiple macros can each have their own unique values assigned to these parameters. These parameters are not passed to macros called from macros (nested macros). They are passed to any files processed through a /INPUT command or a "do loop" processed within the macro. Local Variables Outside of Macros

ANSYS also has a similar set of ARG1 through AR99 scalar parameters that are local to an input file, and are not passed to any macros called by that input file. Thus, once a macro finishes and execution returns to an input file, the values of ARG1 through AR99 revert to whatever values were defined within the input file.

Controlling Program Flow in APDL

When executing an input file, ANSYS is normally restricted to linear program flow; that is, each statement is executed in the order that it is encountered in the listing. However, APDL provides a rich set of commands that you can use to control program flow. These commands are listed here:

Call subroutines (nested macros). Branch unconditionally to a specified location with a macro. Branch based upon a condition to a specified location within a macro. Repeat the execution of a single command, incrementing one or more command parameters. Loop through a section of a macro a specified number of times.

Control Functions Quick Reference The table below describes APDL commands that perform control functions within macros.

Page 20: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 20

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

Page 21: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

________________________________________________________________________________________

________________________________________________________________________________________ 21

Υπολογιστικές Μέθοδοι στις Κατασκευές 8ο εξάμηνο

APDL offers eight comparison operators. Briefly these are: EQ Equal (for VAL1 = VAL2) NE Not equal (for VAL1 ≠ VAL2) LT Less than (for VAL1 < VAL2) GT Greater than (for VAL1 > VAL2) LE Less than or equal (for VAL1 ≤ VAL2) GE Greater than or equal (for VAL1 ≥ VAL2) ABLT Absolute values of VAL1 and VAL2 before < operation ABGT Absolute values of VAL1 and VAL2 before > operation

Page 22: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Οδηγίες για την Άσκηση

• Batch μέσω Matlab

• ANSYS σε SolidWorks

Page 23: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Οδηγίες για το Matlab-Batch

Page 24: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Βήμα 1 Διαβάζετε τον κώδικα της εκφώνηση από εξωτερικό αρχείο που έχετε δημιουργήσει.

Page 25: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Βήμα 1 Το αρχείο .txt περιέχει το κώδικα που βρίσκεται στο παράρτημα Α της εκφώνησης

Page 26: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Βήμα 1 Μόλις πατήσετε ΟΚ προκύπτει η αρχική γεωμετρία

Page 27: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Βήμα 2 Αφαιρείται τον όγκο που επιθυμείτε παραμετρικά.

Αν επιλέξετε τον (b) τρόπο παραμετροποίησης, η εισαγωγή αρχείου γίνεται με την εντολή

/Input,’filename’,’extension’, ‘directory’, , 0

π.χ.

Page 28: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Βήματα 3-7 • Επιλέγετε το πεπερασμένο στοιχείο που δίνεται στην εκφώνηση

• Βάζετε τα Material Properties

• Κάνετε το πλέγμα

• Βάζετε στηρίξεις και φορτία

• Λύνετε το πρόβλημα

• Βλέπετε τουλάχιστον 1 φορά τα αποτελέσματα που σας ενδιαφέρουν από το List Results

• Κάνετε αποθήκευση όλων και έξοδος

Page 29: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Βήμα 8 Κάνετε untick την επιλογή “Save Existing Output Files From Batch Runs”.

Page 30: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Βήματα 9-12

• Συνίσταται να τρέχετε το Batch σε ξεχωριστό directory από αυτό που βρίσκεται το .log file

• Τρέχετε πρώτη φορά το Batch χειροκίνητα (για να δημιουργηθεί φάκελος εργασίας).

• Φτιάχνετε κώδικα της επιλογής σας στο Matlab, ο οποίος τρέχει το Batch και βελτιστοποιεί το πρόβλημα σας.

• Την τελική μορφή την εισάγετε στο SolidWorks (σε μορφή IGES) και παράγετε το αρχείο .SLDPRT με το όνομά σας χαραγμένο πάνω στο τεμάχιο.

Page 31: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Χρήσιμες εντολές MATLAB

Page 32: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

• fileID=fopen(‘directory\file_name.extension’,’permission’) Ανοίγει το επιθυμητό αρχείο με την άδεια που δίνει ο χρήστης.

‘ r ’ Open file for reading

‘ w’ Open or create a file for writing. Discard existing contents,

if any.

‘ a’ Open or create new file for writing. Append data to the

end of the file.

‘ r+’ Open file for reading and writing.

‘ w+’ Open or create new file for reading and writing. Discard existing

contents, if any.

‘ a+’ Open or create new file for reading and writing. Append data to

the end of the file.

Permissions:

Page 33: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

• feof(fileID) Ελέγχει αν το αρχείο έφτασε στο τέλος του. Αν το αρχείο έφτασε στο τέλος επιστρέφει την τιμή 1 αλλιώς επιστρέφει 0. • fgets(fileID) Διαβάζει την επόμενη γραμμή του αρχείου. • frewind(fileID) Γυρίζει στην πρώτη γραμμή του αρχείου. • fclose(fileID) κλείνει το αρχείο που έχετε ανοίξει, του οποίου έχετε δώσει όνομα fileID κατά την κλήση της ρουτίνας fopen.

Page 34: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

• fprintf(fileID, formatSpec, A1, A2,…,An) εκτυπώνει στο αρχείο το επιθυμητό περιεχόμενο και διαγράφει ότι υπήρχε μέσα πριν. Τα formatSpecs «ενημερώνουν» την εντολή, για το τι είδος στοιχείου πρόκειται να γραφτεί στο αρχείο.

Value Type Type in format spec

Integer, signed %d or %i

Integer, unsigned %u

Floating point number %f

Exponential notation, i.e. 3.14e+00 %e

Single character %c

String of characters %s

formatSpec:

Page 35: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Οδηγίες SolidWorks

Page 36: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Ανοίγετε με το ANSYS το .log file που προέκυψε μετά τη βελτιστοποίηση από το menu: File Read Input From

Page 37: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

Εξάγετε την τελική γεωμετρία σε μορφή .iges από το menu: File Export

Page 38: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

To όνομα του αρχείου θα πρέπει να είναι στη μορφή onoma-epitheto.iges

Page 39: YMK02-PAPADOPOULOS-02111066-27.03courseware.mech.ntua.gr/ml23388/lecture_pdfs/MATLAB-ANSYS-v02… · γεωμετρία σε solidworks part προσοχή: όχι drawing!). to παράρτημα

• Κάνετε open το .iges αρχείο από το SolidWorks

• Κάνετε engrave το όνομά σας πάνω στο 3D τεμάχιο. (Βλ. 1ο Μάθημα SolidWorks)

• Αποθηκεύετε σε μορφή .SLDPRT