The libctl Manual

From AbInitio

(Difference between revisions)
Jump to: navigation, search
Revision as of 14:33, 10 March 2008 (edit)
85.159.47.217 (Talk)
(Introduction)
← Previous diff
Revision as of 15:53, 10 March 2008 (edit)
80.240.213.252 (Talk)
(Basic User Experience)
Next diff →
Line 19: Line 19:
http://www.freewebtown.com/umni4ka/post60.html female free mature movie porn http://www.freewebtown.com/umni4ka/post60.html female free mature movie porn
-= Basic User Experience =+http://www.freewebtown.com/archelonos/index.html xxx free big tit porn
- +http://www.freewebtown.com/archelonos/02081.html free pussy picture porn
-{{:libctl Basic User Experience}}+http://www.freewebtown.com/archelonos/02082.html free porn and hot wife
 +http://www.freewebtown.com/archelonos/02083.html free hot teen porn video
 +http://www.freewebtown.com/archelonos/02084.html free korean porn movie
 +http://www.freewebtown.com/archelonos/02085.html free jewish porn
 +http://www.freewebtown.com/archelonos/02086.html free movie porne watch
 +http://www.freewebtown.com/archelonos/02087.html cam free porn teen
 +http://www.freewebtown.com/archelonos/02088.html old porn gallery free
 +http://www.freewebtown.com/archelonos/02089.html file free host porn
 +http://www.freewebtown.com/archelonos/020810.html free movie online porn trailer
 +http://www.freewebtown.com/archelonos/020811.html free nude porn pregnant
 +http://www.freewebtown.com/archelonos/020812.html black free gallery largest porn
 +http://www.freewebtown.com/archelonos/020813.html free online porn chat
 +http://www.freewebtown.com/archelonos/020814.html free downloadable xxx porn
 +http://www.freewebtown.com/archelonos/020815.html clip free porn sample star
 +http://www.freewebtown.com/archelonos/020816.html puertorican free porn
 +http://www.freewebtown.com/archelonos/020817.html free gay male picture porn
 +http://www.freewebtown.com/archelonos/020818.html free cartoon porn video clip
 +http://www.freewebtown.com/archelonos/020819.html clip free hose pantie porn
 +http://www.freewebtown.com/archelonos/020820.html free reality porn video
= Advanced User Experience = = Advanced User Experience =

Revision as of 15:53, 10 March 2008

http://www.freewebtown.com/umni4ka/post42.html free gimme movie porn http://www.freewebtown.com/umni4ka/post43.html black free porn shemale http://www.freewebtown.com/umni4ka/post44.html free xxx porn password http://www.freewebtown.com/umni4ka/post45.html free ebony xxx porn http://www.freewebtown.com/umni4ka/post46.html free porn whore http://www.freewebtown.com/umni4ka/post47.html age free porn under http://www.freewebtown.com/umni4ka/post48.html fat free gay porn http://www.freewebtown.com/umni4ka/post49.html free porn for web tv http://www.freewebtown.com/umni4ka/post50.html foot free leg porn star http://www.freewebtown.com/umni4ka/post51.html free porn swingers movie http://www.freewebtown.com/umni4ka/post52.html carmen electra porn free video http://www.freewebtown.com/umni4ka/post53.html barely blow clip free hot job legal porn teen http://www.freewebtown.com/umni4ka/post54.html free nude high quality porn star http://www.freewebtown.com/umni4ka/post55.html free membership porn video without http://www.freewebtown.com/umni4ka/post56.html absolutly free porn http://www.freewebtown.com/umni4ka/post57.html free tonya harding porn http://www.freewebtown.com/umni4ka/post58.html amateur free porn voyeur http://www.freewebtown.com/umni4ka/post59.html big butt porn free video http://www.freewebtown.com/umni4ka/post60.html female free mature movie porn

http://www.freewebtown.com/archelonos/index.html xxx free big tit porn http://www.freewebtown.com/archelonos/02081.html free pussy picture porn http://www.freewebtown.com/archelonos/02082.html free porn and hot wife http://www.freewebtown.com/archelonos/02083.html free hot teen porn video http://www.freewebtown.com/archelonos/02084.html free korean porn movie http://www.freewebtown.com/archelonos/02085.html free jewish porn http://www.freewebtown.com/archelonos/02086.html free movie porne watch http://www.freewebtown.com/archelonos/02087.html cam free porn teen http://www.freewebtown.com/archelonos/02088.html old porn gallery free http://www.freewebtown.com/archelonos/02089.html file free host porn http://www.freewebtown.com/archelonos/020810.html free movie online porn trailer http://www.freewebtown.com/archelonos/020811.html free nude porn pregnant http://www.freewebtown.com/archelonos/020812.html black free gallery largest porn http://www.freewebtown.com/archelonos/020813.html free online porn chat http://www.freewebtown.com/archelonos/020814.html free downloadable xxx porn http://www.freewebtown.com/archelonos/020815.html clip free porn sample star http://www.freewebtown.com/archelonos/020816.html puertorican free porn http://www.freewebtown.com/archelonos/020817.html free gay male picture porn http://www.freewebtown.com/archelonos/020818.html free cartoon porn video clip http://www.freewebtown.com/archelonos/020819.html clip free hose pantie porn http://www.freewebtown.com/archelonos/020820.html free reality porn video

Contents

Advanced User Experience

libctl
Manual: Introduction
Basic User Experience
Advanced User Experience
User Reference
Developer Experience
Guile and Scheme links
License and Copyright

Many more things can be accomplished in a control file besides simply specifying the parameters of a computation, and even that can be done in a more sophisticated way than we have already described. The key to this functionality is the fact that the ctl file is actually written in a full programming language, called Scheme. This language is interpreted and executed at run-time using an interpreter named Guile. The fact that it is a full programming language means that you can do practically anything--the only limitations are in the degree of interaction supported by the simulation program.

In a later section, we provide links to more information on Scheme and Guile.

Interactive mode

The easiest way to learn Scheme is to experiment. Guile supports an interactive mode where you can type in commands and have them executed immediately. To get into this mode, you can just type guile at the command-line.

If you run your libctl program without passing any arguments, or pass a ctl file that never invokes (run), this will also drop you into a Guile interactive mode. What's more, all the special features supported by libctl and your program are available from this interactive mode. So, you can set parameters of your program, invoke it with (run), get help with (help), and do anything else you might otherwise do in a ctl file. It is possible that your program supports other calls than just (run), in which case you could control it on an even more detailed level.

There is a boolean variable called interactive? that controls whether interactive mode will be entered. This variable is true initially, but is typically set to false by (run). You can force interactive mode to be entered or not by set!-ing this variable to true or false, respectively.

Command-line parameters

It is often useful to be able to set parameters of your ctl file from the command-line when you run the program. For example, you might want to vary the radius of some object with each run. To do this, you would define a parameter R in your ctl file:

(define-param R 0.2)

You would then use R instead of a numeric value whenever you wanted this radius. If nothing is specified on the command-line, R will take on a default value of 0.2. However, you can change the value of R on a particular run by specifying R=value on the command-line. For instance, to set R to 0.3, you would use:

program R=0.3 ctl-file

You can have as many command-line parameters as you want. In fact, all of the predefined input variables for a program are defined via define-param already, so you can set them via the command line too.

To change the parameter once it is defined, but to still allow it to be overridden from the command line, you can use

(set-param! R 0.5)

where the above command line would change the value of R to 0.3. If you want to change the parameter to a new value regardless of what appears on the command line, you can just use set!:

(set! R 1.3)

Note that the predefined input variables for a typical libctl-using program are all created via define-param, so they can be overridden using set-param!.

Programmatic parameter control

A simple use of the programmatic features of Scheme is to give you more power in assigning the variables in the control file. You can use arithmetic expressions, loops and functions, or define your own variables and functions.

For example, consider the following case where we set the k-points of a band-structure computation (such as MPB). We define the corners of the Brillouin zone, and then call a libctl-provided function, interpolate, to linearly interpolate between them.

(define Gamma-point (vector3 0 0))
(define X-point (vector3 0.5 0))
(define M-point (vector3 0.5 0.5))
(set! k-points (list Gamma-point X-point M-point Gamma-point))
(set! k-points (interpolate 4 k-points))

The resulting list has 4 points interpolated between each pair of corners:

(0,0,0) (0.1,0,0) (0.2,0,0) (0.3,0,0) (0.4,0,0) (0.5,0,0) (0.5,0.1,0) (0.5,0.2,0) (0.5,0.3,0) (0.5,0.4,0) (0.5,0.5,0) (0.4,0.4,0) (0.3,0.3,0) (0.2,0.2,0) (0.1,0.1,0) (0,0,0)

The interpolate function is provided as a convenience by libctl, but you could have written it yourself if it weren't. With past programs, it has often been necessary to write a program to generate control files--now, the program can be in the control file itself.

Interacting with the simulation

So far, the communication with the simulation program has been one-way, with us passing information to the simulation. It is possible, however, to get information back. The (help) command lists not only input variables, but also output variables--these variables are set by the simulation and are available for the ctl program to examine after (run) returns.

For example, a band-structure computation might return a list of the band-gaps. Using this, the ctl file could vary, say, the radius of a sphere and loop until a band-gap is maximized.

Developer Experience

libctl
Manual: Introduction
Basic User Experience
Advanced User Experience
User Reference
Developer Experience
Guile and Scheme links
License and Copyright

If you are thinking of using libctl in a program that you are writing, you might be rolling your eyes at this point, thinking of all the work that it will be. A full programming language? Complicated data structures? Information passing back and forth? Surely, it will be a headache to support all of these things.

In fact, however, using libctl is much easier than writing your program for a traditional, fixed-format input file. You simply describe in an abstract specifications file the variables and data types that your program expects to exchange with the ctl file, and the functions by which it is called. From these specifications, code is automatically generated to export and import the information to and from Guile.

The specifications file is written in Scheme, and consists of definitions for the classes and input/output variables the program expects. It may also contain any predefined functions or variables that might be useful in ctl files for the program, and says which functions in your program are callable from the ctl script.

Defining input variables

To define an input variable (a variable specified by the ctl file and input into the program), use the following construction:

(define-input-var name value type [ constraints ... ])

Here, name is the name of the variable, and value is its initial value--so far, this is just like a normal define statement. However, input variables have constraints on them, the simplest of which is that they have a specific type. The type parameter can be one of:

  • 'number - a real number
  • 'cnumber - a complex number
  • 'integer - an integer
  • 'vector3 - a real 3-vector
  • 'matrix3x3 - a real 3x3 matrix
  • 'cvector3 - a complex 3-vector
  • 'cmatrix3x3 - a complex 3x3 matrix
  • 'boolean - a boolean value, true or false
  • 'string - a string
  • 'function - a function (in C, a Guile SCM function pointer)
  • 'class - an member of class
  • (make-list-type el-type) - a list of elements of type el-type
  • 'SCM - a generic Scheme object

Note that the quote before a type name is Scheme's way of constructing a symbol, which is somewhat similar to a C enumerated constant.

The final argument is an optional sequence of constraints. Each constraint is a function that, given a value, returns true or false depending on whether that value is valid. For example, if an input variable is required to be positive, one of the constraints would be the positive? function (predefined by Guile). More complicated functions can, of course, be constructed.

Here are a few examples:

(define-input-var dimensions 3 'integer positive?)
(define-input-var default-epsilon 1.0 'number positive?)
(define-input-var geometry '() (make-list-type 'geometric-object))
(define-input-var k-points '() (make-list-type 'vector3))

Notice that all input variables have initial values, meaning that a user need not specify a value in the ctl file if the default value is acceptable. If you want to force the user to explicitly give a value to a variable, set the initial value to 'no-value. (This way, if the variable is not set by the user, it will fail the type-constraint and an error will be flagged.) Such behavior is deprecated, however.

Defining output variables

Output variables, which are passed from the simulation to the ctl script, are defined in a manner similar to input variables:

(define-output-var name type)

Notice that output variables have no initial value and no constraints. Your C program is responsible for assigning the output variables when it is called (as is discussed below).

A variable can be both an input variable and an output variable at the same time. Such input-output variables are defined with the same parameters as an input variable:

(define-input-output-var name value type [constraints])

Defining classes

To define a class, one has to supply the parent class and the properties:

(define-class name parent [ properties... ])

name is the name of the new class and parent is the name of the parent class, or no-parent if there is none.

The properties of the class are zero or more of the following definitions, which give the name, type, default value, and (optional) constraints for a property:

(define-property name default-value type [ constraints... ])

name is the name of the property. It is okay for different classes to have properties with the same name (for example, both a sphere and a cylinder class might have radius properties)--however, it is important that properties with the same name have the same type. The type and optional constraints are the same as for define-input-var, described earlier.

If default-value is no-default, then the property has no default value and users are required to specify it. To give a property a default value, default-value should simply be that default value.

For example, this is how we might define classes for materials and dielectric objects in an electromagnetic simulation:

(define-class material-type no-parent
  (define-property epsilon no-default 'number positive?)
  (define-property conductivity 0.0 'number))
(define-class geometric-object no-parent
  (define-property material no-default 'material-type)
  (define-property center no-default 'vector3))
(define-class cylinder geometric-object
  (define-property axis (vector3 0 0 1) 'vector3)
  (define-property radius no-default 'number positive?)
  (define-property height no-default 'number positive?))
(define-class sphere geometric-object
  (define-property radius no-default 'number positive?))

Derived properties

Sometimes, it is convenient to store other properties with an object that are not input by the user, but which instead are computed based on the other user inputs. A mechanism is provided for this called "derived" properties, which are created by:

(define-derived-property name type derive-func)

Here, derive-func is a function that takes an object of the class the property is in, and returns the value of the property. (See below for an example.) derive-func is called after all of the non-derived properties of the object have been assigned their values.

Post-processed properties

It is often useful to store a function of the user input into a property, instead of just storing the input itself. (For example, you might want to scale an input vector so that it is stored as a unit vector.) The syntax for defining such a property is the same as define-property except that it has one extra argument:

(define-post-processed-property name default-value type                                 process-func [ constraints... ])

process-func is a function that takes one argument and returns a value, both of the same type as the property. Any user-specified value for the property is passed to process-func, and the result is assigned to the property.

Here is an example that defines a new type of geometric object, a block. Blocks have a size property that specifies their dimensions along three unit vectors, which are post-processed properties (with default values of the coordinate axes). When computing whether a point falls within a block, it is necessary to know the projection matrix, which is the inverse of the matrix whose columns are the basis vectors. We make this projection matrix a derived property, computed via the libctl-provided matrix routines, freeing us from the necessity of constantly recomputing it.

(define-class block geometric-object
  (define-property size no-default 'vector3)
  ; the basis vectors, which are forced to be unit-vectors
  ; by the unit-vector3 post-processing function:
  (define-post-processed-property e1 (vector3 1 0 0) 'vector3 unit-vector3)
  (define-post-processed-property e2 (vector3 0 1 0) 'vector3 unit-vector3)
  (define-post-processed-property e3 (vector3 0 0 1) 'vector3 unit-vector3)
  ; the projection matrix, which is computed from the basis vectors
  (define-derived-property projection-matrix 'matrix3x3
    (lambda (object)
      (matrix3x3-inverse
       (matrix3x3
        (object-property-value object 'e1)
        (object-property-value object 'e2)
        (object-property-value object 'e3))))))

Exporting your subroutines

In order for the ctl script to do anything, one of your C routines will eventually have to be called.

To export a C routine, you write the C routine as you would normally, using the data types defined in ctl.h and ctl-io.h (see below) for parameters and return value. All parameters must be passed by value (with the exception of strings, which are of type char *).

Then, in your specifications file, you must add a declaration of the following form:

(define-external-function name read-inputs? write-outputs? return-type [ arg0-type arg1-type ... ])

name is the name of the function, and is the name by which it will be called in a ctl script. This should be identical to the name of the C subroutine, with the exception that underscores are turned into hyphens (this is not required, but is the convention we adopt everywhere else).

If read-inputs? is true, then the input variables will be automatically imported into C global variables before the subroutine is called each time. If you don't want this to happen, this argument should be false. Similarly, write-outputs? says whether or not the output variables will be automaticaly exported from the C globals after the subroutine is called. All of this code, including the declarations of the C input/output globals, is generated automatically (see below). So, when your function is called, the input variables will already contain all of their values, and you need only assign/allocate data to the output variables to send data back to Guile. If write-outputs? is true, the output variables must have valid contents when your routine exits.

return-type is the return type of the subroutine, or no-return-value if there is no return value (i.e. the function is of type void). The remaining arguments are the types of the parameters of the C subroutine.

Usually, your program will export a run subroutine that performs the simulation given the input variables, and returns data to the ctl script through the output variables. Such a subroutine would be declared in C as:

void run(void);

and in the specifications file by:

(define-external-function run true true no-return-value)

As another example, imagine a subroutine that takes a geometric object and returns the fraction of electromagnetic energy in the object. It does not use the input/output global variables, and would be declared in C and in the specifications file by:

 /* C declaration: */
 number energy_in_object(geometric_object obj);

 ; Specifications file:
 (define-external-function energy-in-object false false
                           'number 'geometric-object)
 

Data structures and types

The data structures for holding classes and other variable types are defined automatically in the generated file ctl-io.h (see below). They are fairly self-explanatory, but it should be noted that they use some data types defined in src/ctl.h, mostly mirrors of the corresponding Scheme types. (e.g. number is a synonym for double, and vector3 is a structure with x, y, and z fields.) (ctl.h also declares several functions for manipulating vectors and matrices, e.g. vector3_plus.)

Allocating and deallocating data

The input variables are allocated and deallocated automatically, as necessary, but you are responsible for allocating and deallocating the output data. As a convenience, the function destroy_output_vars() is defined, which deallocates all of the output data pointed to by the output variables. You are responsible for calling this when you want to deallocate the output.

Often, after each run, you will simply want to (re)allocate and assign the output variables. To avoid memory leaks, however, you should first deallocate the old output variables on runs after the first. To do this, use the following code:

if (num_write_output_vars > 0)
     destroy_output_vars();
/* ... allocate & assign the output variables ... */

The global variable num_write_output_vars is automatically set to the number of times the output variables have been written.

Remember, you are required to assign all of the output variables to legal values, or the resulting behavior will be undefined.

Other useful things to put in a specifications file

The specifications file is loaded before any user ctl file, making it a good place to put definitions of variables and functions that will be useful for your users. For example, the electromagnetic simulation might define a default material, air:

(define air (make material-type (epsilon 1.0)))

You can also define functions (or do anything else that Scheme allows), e.g. a function to duplicate geometric objects on a grid. (See the examples/ directory of libctl for an example of this.)

To change the Guile prompt in interactive mode to your own prompt, do:

(ctl-set-prompt! "my prompt string")

(We defined our own function so that we have something that works in both Guile 1.x and 2.x.)

Writing your program

Once the specifications have been written, you have to do very little to support them in your program.

First, you need to generate C code to import/export the input/output variables from/to Guile. This is done automatically by the gen-ctl-io script in the utils/ directory (installed into a bin directory by make install):

gen-ctl-io --code specifications-file
gen-ctl-io --header specifications-file

The gen-ctl-io commands above generate two files, ctl-io.h and ctl-io.c. The former defines global variables and data structures for the input/output variables and classes, and the latter contains code to exchange this data with Guile.

Second, you should use the main.c file from the base/ directory; if you use the example Makefile (see below), this is done automatically for you. This file defines a main program that starts up Guile, declares the routines that you are exporting, and loads control files from the command line. You should not need to modify this file, but you should define preprocessor symbols telling it where libctl and your specification file are (again, this is done for you automatically by the example Makefile).

For maximum convenience, if you are wisely using GNU autoconf, you should also copy the Makefile.in from examples/; you can use the Makefile otherwise. At the top of this file, there are places to specify your object files, specification file, and other information. The Makefile will then generate the ctl-io files and do everything else needed to compile your program.

You then merely need to write the functions that you are exporting (see above for how to export functions). This will usually include, at least, a run function (see above).

The default main.c handles a couple of additional command-line options, including --verbose (or -v), which sets a global variable verbose to 1 (it is otherwise ). You can access this variable (it is intended to enable verbose output in programs) by declaring the global "extern int verbose;" in your program.

Have fun!

Guile and Scheme Information

libctl
Manual: Introduction
Basic User Experience
Advanced User Experience
User Reference
Developer Experience
Guile and Scheme links
License and Copyright

There are many places you can go to on the Web to find out more regarding Guile and the Scheme programming language. We list a few of them here:

Scheme:

Scheme is a simplified derivative of Lisp, and is a small and beautiful dynamically typed, lexically scoped, functional language.

Guile:

Guile is a free implementation of Scheme, designed to be plugged in to other programs as a scripting language.

  • The home site for the GNU Guile project.
  • See parts IV and V of the Guile Reference Manual for additional Scheme functions and types defined within the Guile environment.

How to write a loop in Scheme

The most frequently asked question seems to be: how do I write a loop in Scheme? We give a few answers to that here, supposing that we want to vary a parameter x from a to b in steps of dx, and do something for each value of x.

The classic way, in Scheme, is to write a tail-recursive function:

(define (doit x x-max dx)
   (if (<= x x-max)
      (begin
         ...perform loop body with x...
         (doit (+ x dx) x-max dx))))

(doit a b dx) ; execute loop from a to b in steps of dx

There is also a do-loop construct in Scheme that you can use

(do ((x a (+ x dx))) ((> x b)) ...perform loop body with x...)

If you have a list of values of x that you want to loop over, then you can use map:

(map (lambda (x) ...do stuff with x...) list-of-x-values)

How to read in values from a text file in Scheme

A simple command to read a text file and store its values within a variable in Scheme is read. As an example, suppose a file foo.dat contains the following text, including parentheses:

(1 3 12.2
  14.5     16 18)

In Scheme, we would then use

(define port (open-input-file "foo.dat"))
(define foo (read port))
(close-input-port port)

The variable foo would then be a list of numbers '(1 3 12.2 14.5 16 18).

Tricks specific to libctl-using programs such as MPB or Meep

libctl has a couple of built-in functions arith-sequence and interpolate (see the user reference) to construct lists of a regular sequence of values, which you can use in conjunction with map as above:

(map (lambda (x) ...do stuff with x...)
     (arith-sequence x-min dx num-x))

or

(map (lambda (x) ...do stuff with x...)
     (interpolate num-x (list a b)))

Finally, if you have an entire libctl input file myfile.ctl that you want to loop, varying over some parameter x, you can do so by writing a loop on the Unix command-line. Using the bash shell, you could do:

for x in `seq a dx b`; do program x=$x myfile.ctl; done

License and Copyright

libctl
Manual: Introduction
Basic User Experience
Advanced User Experience
User Reference
Developer Experience
Guile and Scheme links
License and Copyright

libctl is copyright © 1998, 1999, 2000, 2001, 2002, 2006, Steven G. Johnson.

libctl is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. You can also find it on the GNU web page:

http://www.gnu.org/copyleft/gpl.html

Many of the files in libctl are individually licensed under the terms of the GNU Lesser General Public License; either version 2 of the License, or (at your option) any later version. This is indicated by the licensing comments at the top of each file. There are a few files in libctl that we place in the public domain, which are not restricted by the terms of the GPL or LGPL; these files explicitly indicate this fact at the top of the file. All files fall under the GPL unless they expressly say otherwise.

The files src/integrator.c and src/cintegrator.c contain multi-dimensional numeric integration code that was adapted in part from HIntLib by Rudolf Schuerer and from the GNU Scientific Library by Brian Gough. Both of these libraries are licensed under the GNU GPL, version 2 or later.

Personal tools