powerflow/init.cpp

00001 // $Id: init.cpp,v 1.29 2008/02/04 23:08:12 natet Exp $
00002 
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #include <errno.h>
00006 #include <math.h>
00007 
00008 #include "gridlabd.h"
00009 
00010 #define _POWERFLOW_CPP
00011 #include "powerflow.h"
00012 #undef  _POWERFLOW_CPP
00013 
00014 #include "capacitor.h"
00015 #include "fuse.h"
00016 #include "line.h"
00017 #include "link.h"
00018 #include "load.h"
00019 #include "meter.h"
00020 #include "node.h"
00021 #include "regulator.h"
00022 #include "relay.h"
00023 #include "transformer.h"
00024 
00025 bool show_matrix_values = 0;
00026 
00027 EXPORT CLASS *init(CALLBACKS *fntable, MODULE *module, int argc, char *argv[])
00028 {
00029     if (!set_callback(fntable)) {
00030         errno = EINVAL;
00031         return NULL;
00032     }
00033     
00034     // this variable controls whether matrices are printed out
00035     gl_global_create("show_matrix_values",PT_bool,&show_matrix_values,NULL);
00036 
00037     // register each object class by creating default instance
00038     CLASS *first = (new node(module))->oclass;
00039     new link(module);
00040     new capacitor(module);
00041     new fuse(module);
00042     new meter(module);
00043     new line(module);
00044     new line_spacing(module);
00045     new overhead_line(module);
00046     new underground_line(module);
00047     new overhead_line_conductor(module);
00048     new underground_line_conductor(module);
00049     new line_configuration(module);
00050     new relay(module);
00051     new transformer_configuration(module);
00052     new transformer(module);
00053     new load(module);
00054     new regulator_configuration(module);
00055     new regulator(module);
00056     new triplex_node(module);
00057     new triplex_line(module);
00058     new triplex_line_configuration(module);
00059     new triplex_line_conductor(module);
00060 
00061     /* always return the first class registered */
00062     return first;
00063 }
00064 
00065 
00066 CDECL int do_kill()
00067 {
00068     /* if global memory needs to be released, this is a good time to do it */
00069     return 0;
00070 }
00071 
00072 EXPORT int check()
00073 {
00074     /* check each link to make sure it has a node at either end */
00075     FINDLIST *list = gl_find_objects(FL_NEW,FT_MODULE,SAME,"powerflow",NULL);
00076     OBJECT *obj=NULL;
00077 
00078     /* check from/to info on links */
00079     while (obj=gl_find_next(list,obj))
00080     {
00081         if (gl_object_isa(obj,"link"))
00082         {
00083             link *pLink = OBJECTDATA(obj,link);
00084             OBJECT *from = pLink->from;
00085             OBJECT *to = pLink->to;
00086             if (from==NULL)
00087                 gl_error("link %s (%s:%d) from object is not specified", pLink->get_name(), pLink->oclass->name, pLink->get_id());
00088             else if (!gl_object_isa(from,"node"))
00089                 gl_error("link %s (%s:%d) from object is not a node", pLink->get_name(), pLink->oclass->name, pLink->get_id());
00090             if (to==NULL)
00091                 gl_error("link %s (%s:%d) to object is not specified", pLink->get_name(), pLink->oclass->name, pLink->get_id());
00092             else if (!gl_object_isa(to,"node"))
00093                 gl_error("link %s (%s:%d) to object is not a node", pLink->get_name(), pLink->oclass->name, pLink->get_id());
00094         }
00095     }
00096 
00097     return 0;
00098 }
00099 

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy