02.04.2013 Views

Welcome to Adams/Solver Subroutines - Kxcad.net

Welcome to Adams/Solver Subroutines - Kxcad.net

Welcome to Adams/Solver Subroutines - Kxcad.net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

User-Written <strong>Subroutines</strong><br />

<strong>Welcome</strong> <strong>to</strong> <strong>Adams</strong>/<strong>Solver</strong> <strong>Subroutines</strong><br />

User-written subroutines, while a little more difficult <strong>to</strong> use, provide a degree of generality, efficiency<br />

and flexibility that function expressions do not. <strong>Subroutines</strong> allow you <strong>to</strong> use FORTRAN-77 features <strong>to</strong><br />

define functions not otherwise available with <strong>Adams</strong>/<strong>Solver</strong>, and <strong>to</strong> tailor <strong>Adams</strong>/<strong>Solver</strong> <strong>to</strong> your needs.<br />

By linking in user-written subroutines, you don't lose any efficiency or decrease the simulation speed.<br />

<strong>Subroutines</strong> and function expressions serve essentially the same purpose: they both allow you <strong>to</strong> define<br />

non-standard input <strong>to</strong> <strong>Adams</strong>.<br />

Function expressions are easier <strong>to</strong> work with, because you don't have <strong>to</strong> compile or link programs. Also,<br />

they work on every machine on which <strong>Adams</strong>/<strong>Solver</strong> is available. User-written subroutines, however,<br />

are much more general. The power of the programming language is available <strong>to</strong> define modeling<br />

elements or special output.<br />

On the other hand, function expressions support a limited set of programming constructs. Therefore,<br />

complicated phenomena, especially those involving a lot of logic, cannot be easily described using<br />

function expressions.<br />

You use user-written subroutines when:<br />

• Dataset functions become awkward.<br />

• You need <strong>to</strong> define functions used by a group of users.<br />

• Statements, such as GSE and UCON, require them.<br />

• You want <strong>to</strong> control the running of complex simulations that require decision-making logic.<br />

Write user-written subroutines with care because incorrectly coded subroutines are very difficult <strong>to</strong><br />

debug. Follow a crawl-walk-run approach for developing user subroutines. Start with simple versions of<br />

a user-written subroutine, make sure it works as desired, then gradually increase the complexity of the<br />

subroutine. Make sure that there are no compiler or linker warnings when your subroutine is linked in<strong>to</strong><br />

<strong>Adams</strong>.<br />

The "C" style interface <strong>to</strong> user subroutines has been enhanced <strong>to</strong> replace some of the arguments with a<br />

pointer <strong>to</strong> a structure. This will require changes <strong>to</strong> your user subroutine source code. If you are using the<br />

fortran style interface <strong>to</strong> user subroutines you will not be effected and no changes will be required.<br />

The new argument list <strong>to</strong> the "C" style interface replaces some of the arguments with a pointer <strong>to</strong> a<br />

structure. This structure contains the replaced arguments plus additional information. Old arguments<br />

such as ID, PAR, and NPAR have been incorperated in<strong>to</strong> the structure. New arguments such as marker<br />

id's have been added <strong>to</strong> the structure.<br />

CFFSUB<br />

The CFFSUB evaluation subroutine computes a set of friction force values for a CONTACT statement<br />

(C++ or FORTRAN). You can use a CFFSUB when the default friction force routine is not applicable <strong>to</strong><br />

your model.<br />

127

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!