Abstract class Model


The class Model is an abstract class that all models inherit. It provides means for recording the inheritance structure of the models, run-time access to model instantiation, modification of model parameters, and virtual copying of models.

Include file:

#include "inherit.h"

Source code:

inherit.cpp
models.cpp

See also:

SCATMECH HomeInheritanceModel_Ptr<model>

Definition of public and protected elements:

class Model
{
public:
    virtual void AskUser();

    virtual void set_parameter(const string& name,const string& value);
    void set_parameter(const string& parameter, double value);
    void set_parameter(const string& parameter, const COMPLEX& value);

    string get_parameter(const string& parameter);

    void print_parameters(ostream& os);
    void get_parameter_names(StringList& plist) const;   
    ParameterInfo get_parameter_info(const string& parameter) const;

    static Inheritance inheritance;
    virtual const Inheritance& get_inheritance() const;

    void set_recalc(int _recalc=1);
    virtual int get_recalc();

    static void set_quiet(int _quiet);
    static int get_quiet();

    void init();

protected:
    virtual void setup();
    virtual void SETUP();
    static void message(const string& s, bool oneline=true);
};

virtual void AskUser()

The virtual function AskUser queries the user for all parameters needed by the specific model. It always begins by calling its parent's AskUser.

Top of Page

virtual void set_parameter(const string& name,const string& value)
void set_parameter(const string& parameter, double value)
void set_parameter(const string& parameter, const COMPLEX& value)

The virtual function set_parameter allows one to change any model parameter by name. The string name is the name of the parameter, which should always be the same as the name used in the specific model's get_ and set_ functions. For those parameters that take their own parameters, the parameter name is followed by a period, followed by the parameter's parameter. The string value contains the parameter encoded as a string. Each model's function set_parameter should set the variable recalc to 1, and should call its parent's set_parameter, if there is no match to the current parameters. If the parameter does not exist for the current model, then an exception of type SCATMECH_exception is thrown. The second two functions provide encoding of double precision and complex numbers as strings.

Example:

BRDF_Model &model;
model.set_parameter("substrate","1.46");
model.set_parameter("thickness","0.05");

Top of Page

string get_parameter(const string& parameter)

Function that returns a string representation of a specific parameter.

Top of Page

void print_parameters(ostream& os)

Function that prints a complete list of parameter names, values, descriptions, and types to a stream.

Top of Page

void get_parameter_names(StringList& plist) const

Function that retrieves a list of all valid parameters for a given model. The data type StringList is a typedef for std::deque<std::string>.

Top of Page

ParameterInfo get_parameter_info(const string& parameter) const

Function that returns information about a particular parameter. ParameterInfo is a structure defined as

struct ParameterInfo {
    string name;         // The name of the parameter...
    string description;  // A description of the parameter...
    string type;         // The data type for external programs...
    string defaultvalue; // The default value for the parameter...
};

Top of Page

static Inheritance inheritance
virtual const Inheritance& get_inheritance()

Every class inheriting Model has a static member named inheritance of type Inheritance which keeps track of all models which inherit it and its parameters. It enables run-time generation of instances of a class and dynamic access to parameters by name. Accessing a specific model's inheritance directly will allow access to that specific model's parameters, but not those of a child model. Accessing the model's inheritance through the function get_inheritance() will allow access to the parameters of the specific instantiation of the model. In the case of accessing inheritance directly, you do not need an instance of the class, while in the case of using get_inheritance you need an instance.

Top of Page

void init()

Function that sets all parameters to their default values.

void set_recalc(int _recalc)
virtual int get_recalc()

A private variable recalc is set whenever any model parameter is modified. It signals that the function setup() needs to be run. The function get_recalc() can be overridden by a class if it needs to check its member parameters that are Models in themselves.

Top of Page

virtual void setup()

The function setup() is called if the model is evaluated when recalc is nonzero. A child model's setup() should always begin by calling its parent's setup(). This function performs any initialization of the model.

Top of Page

virtual void SETUP()

The function SETUP() should always be called at the beginning of any model function to check to see if recalc is nonzero. If so, it will call the function setup(). A child model's SETUP() should always end by calling its parent's SETUP().

Top of Page

static void message(const string& s, bool oneline=true)

The function message provides member models a means for communicating simple progress reports or warning messages. If the value of oneline is true, the message will be appended with a carriage return, while if it is false, the message will be appended with a carriage return and linefeed. If the value of quiet is true, then the message will not be printed. The message, if quiet is false, will be printed to the standard error stream, by default.

Top of Page


For More Information

SCATMECH Technical Information and Questions
Optical Technology Division (OTD) Home Page
OTD Technical Inquiries
OTD Website Comments

Current SCATMECH version: 6.00 (February 2008)
This page first online: Version 4.00 (July 2003)
This page last modified: Version 6.00 (February 2008)