Пример #1
0
CMreturn NFparseCompContainerFinalize(NFobject_p parent, NFobject_p object) {
    ;
    NFcompModel_p model;

    if (object->Type != NFcompContainer) {
        CMmsgPrint(CMmsgAppError, "This shouldn't have happened in %s:%d!\n", __FILE__, __LINE__);
        return (CMfailed);
        goto Abort;
    }
    switch (parent->Type) {
        case NFcompContainer:
            if (NFobjListAddItem(((NFcompContainer_p) parent)->Components, object) != CMsucceeded) {
                CMmsgPrint(CMmsgAppError, "Error adding component to model in %s:%d\n", __FILE__, __LINE__);
                goto Abort;
            }
        case NFcompModel:
            model = (NFcompModel_p) NFobjectRoot(parent);
            if (NFobjListAddItem(model->Components, object) != CMsucceeded) {
                CMmsgPrint(CMmsgAppError, "Error adding component to model in %s:%d\n", __FILE__, __LINE__);
                goto Abort;
            }
            break;
        default:
            CMmsgPrint(CMmsgAppError, "This shouldn't have happened in %s:%d!\n", __FILE__, __LINE__);
            goto Abort;
    }
    return (CMsucceeded);
    Abort:
    NFobjectFree(object);
    return (CMfailed);
}
Пример #2
0
NFobject_p NFparseModProcessCreate (XML_Parser parser,NFobject_p parent,const char *name, const char **attr) {
	const char *attrib;

	NFmodProcess_p module = (NFmodProcess_p) NULL;
	NFcompModel_p  model;
	NFobjPlugin_p  plugin = (NFobjPlugin_p)  NULL;

	if (parent->Type != NFcompContainer) {
		CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__);
		goto Abort;
	}

	if ((module = (NFmodProcess_p) NFobjectCreate (name,NFmodProcess)) == (NFmodProcess_p) NULL) {
		CMmsgPrint (CMmsgAppError, "Process module creation error in %s:%d\n",__FILE__,__LINE__);
		goto Abort;
	}
	if ((attrib = NFparseGetAttribute (attr, NFobjPluginStr, (char *) NULL)) == (char *) NULL) {
		CMmsgPrint (CMmsgUsrError, "Missing process [%s] plugi in line %d!\n",name, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	model = (NFcompModel_p) NFobjectRoot (parent);
	if ((plugin = NFpluginGet (model->ModPlugins,attrib)) == (NFobjPlugin_p) NULL) {
		CMmsgPrint (CMmsgUsrError, "Modules plugin [%s] loading error in line %d!\n",attrib, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((attrib = NFparseGetAttribute (attr, NFattrMethodStr, (char *) NULL)) == (char *) NULL) {
		CMmsgPrint (CMmsgUsrError, "Missing plugin [%s] method in line %d!\n",plugin->Name, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((module->Initialize = (NFinitializeFunc) NFpluginFunction (plugin, NFfuncInitializeStr, attrib)) == (NFinitializeFunc) NULL) {
		CMmsgPrint (CMmsgUsrError, "Error loding plugin [%s] function [%s] in line %d!\n",plugin->Name, attrib, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((module->Execute    = (NFexecuteFunc)    NFpluginFunction (plugin, NFfuncExecuteStr,   attrib)) == (NFexecuteFunc)    NULL) {
		CMmsgPrint (CMmsgUsrError, "Error loding plugin [%s] function [%s] in line %d!\n",plugin->Name, attrib, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((module->Finalize   = (NFfinalizeFunc)   NFpluginFunction (plugin, NFfuncFinalizeStr,  attrib)) == (NFfinalizeFunc)   NULL) {
		CMmsgPrint (CMmsgUsrError, "Error loading plugin [%s] function [%s] in line %d!\n",plugin->Name, attrib, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	module->Initialize (module->Context);
	if ((module->Context->UserData = (void *) malloc (module->Context->UserDataSize)) == (void *) NULL) {
		CMmsgPrint (CMmsgSysError, "Memory allocation errord in %s:%d\n",__FILE__,__LINE__);
		goto Abort;
	}
	module->Parent = parent;
	CMmsgPrint (CMmsgInfo,"Parameter num: %d Variable num: %d\n", module->Context->ParameterNum, module->Context->VariableNum);
	return ((NFobject_p) module);
Abort:
	if (module != (NFmodProcess_p) NULL) NFobjectFree ((NFobject_p) module);
	return ((NFobject_p) NULL);	
}
Пример #3
0
NFobject_p NFparseCompContainerCreate(XML_Parser parser, NFobject_p parent, const char *name, const char **attr) {
    const char *attrib;
    NFcompContainer_p component = (NFcompContainer_p) NULL;
    NFcompModel_p model;
    NFcomponent_p sibling;
    NFobjList_p componentList;
    NFtimeStep_p timeStep;

    if ((parent->Type != NFcompModel) && (parent->Type != NFcompContainer)) {
        CMmsgPrint(CMmsgAppError, "This shouldn't have happened in %s%d\n", __FILE__, __LINE__);
        goto Abort;
    }
    if ((component = (NFcompContainer_p) NFobjectCreate(name, NFcompContainer)) == (NFcompContainer_p) NULL) {
        CMmsgPrint(CMmsgAppError, "Component creation error in %s:%d\n", __FILE__, __LINE__);
        goto Abort;
    }
    attrib = NFparseGetAttribute(attr, NFcompLayoutStr, NFkeyInheritStr);
    if (strcmp(attrib, NFkeyInheritStr) == 0) {
        if (parent->Type == NFcompContainer)
            component->Domain = ((NFcomponent_p) parent)->Domain;
        else {
            CMmsgPrint(CMmsgUsrError, "Container [%s] in model can't inherit layout in line %d!\n", name,
                       XML_GetCurrentLineNumber(parser));
            goto Abort;
        }
    }
    else {
        switch (parent->Type) {
            case NFcompContainer:
                componentList = ((NFcompContainer_p) parent)->Components;
                break;
            case NFcompModel:
                componentList = ((NFcompModel_p) parent)->Components;
                break;
            default:
                CMmsgPrint(CMmsgUsrError, "This shouldn't have happened in %s,%d!\n", __FILE__, __LINE__);
                goto Abort;
        }
        if ((sibling = (NFcomponent_p) NFobjListFindItemByName(componentList, attrib)) == (NFcomponent_p) NULL) {
            CMmsgPrint(CMmsgUsrError, "Invalid container [%s] layout [%s] in line %d.\n", name, attrib,
                       XML_GetCurrentLineNumber(parser));
            goto Abort;
        }
        component->Domain = sibling->Domain;
    }
    model = (NFcompModel_p) NFobjectRoot(parent);
    attrib = NFparseGetAttribute(attr, NFattrTimeStepStr, "inherit");
    if (strcmp(attrib, NFkeyInheritStr) == 0) {
        switch (parent->Type) {
            case NFcompContainer:
            case NFcompModel:
                component->TimeStep = ((NFcomponent_p) parent)->TimeStep;
                break;
            default:
                CMmsgPrint(CMmsgAppError, "This shouldn't have happened in %s%d!\n", __FILE__, __LINE__);
                goto Abort;
        }
    }
    else {
        if (NFtimeStepSetFromString(component->TimeStep, attrib) == false) {
            CMmsgPrint(CMmsgAppError, "Time step [%s] error in %d!\n", attrib, XML_GetCurrentLineNumber(parser));
            goto Abort;
        }
        if ((timeStep = NFmodelAddTimeStep(model, component->TimeStep)) != component->TimeStep) {
            NFtimeStepFree(component->TimeStep);
            component->TimeStep = timeStep;
        }
    }
    if ((attrib = NFparseGetAttribute(attr, NFattrStatesStr, (char *) NULL)) == (char *) NULL) {
        CMmsgPrint(CMmsgUsrError, "Missing container state in line %d\n", XML_GetCurrentLineNumber(parser));
        goto Abort;
    }
    component->States = CMstrDuplicate(attrib);

    component->Parent = parent;
    return ((NFobject_p) component);
    Abort:
    if (component != (NFcompContainer_p) NULL) NFobjectFree((NFobject_p) component);
    return ((NFobject_p) NULL);
}
Пример #4
0
NFobject_p NFparseModInterfaceCreate (XML_Parser parser,NFobject_p parent,const char *name, const char **attr) {
	const char *attrib;
	NFmodInterface_p module   = (NFmodInterface_p) NULL;
	NFnumVariable_p  inputVar;
	NFobject_p       component;
	NFobjList_p list;

	if ((parent->Type != NFcompContainer) || (parent->Parent == (NFobject_p) NULL))  {
		CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__);
		goto Abort;
	}
	if ((attrib = NFparseGetAttribute (attr, NFattrRelationStr, (char *) NULL)) == (char *) NULL) {
		CMmsgPrint (CMmsgUsrError, "Missing interface [%s] relation in %d!\n",name, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if      (strcmp (attrib,NFkeyRootStr)   == 0) {
		component = NFobjectRoot (parent);
		if (component->Type == NFcompModel) list = ((NFcompModel_p) component)->Components;
		else {
			CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__);
			goto Abort;
		}
	}
	else if (strcmp (attrib,NFkeyParentStr) == 0) {
		component = parent->Parent;
		switch (component->Type) {
		case NFcompModel:     list = ((NFcompModel_p)     component)->Components; break;
		case NFcompContainer: list = ((NFcompContainer_p) component)->Components; break;
		default:
			CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__);
			goto Abort;
		}
	}
	else if (strcmp (attrib,NFkeyOwnStr)    == 0) list = ((NFcompModel_p) parent)->Components;

	if ((attrib = NFparseGetAttribute (attr, NFcomponentStr, (char *) NULL)) == (char *) NULL) {
		CMmsgPrint (CMmsgUsrError, "Missing interface [%s] component in %d!\n",name, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((component = NFobjListFindItemByName (list,attrib)) == (NFobject_p) NULL) {
		CMmsgPrint (CMmsgUsrError, "Invalid interface [%s] component [%s] in line %d!\n",name, attrib, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((attrib = NFparseGetAttribute (attr, NFcomponentStr, (char *) NULL)) == (char *) NULL) {
		CMmsgPrint (CMmsgUsrError, "Missing interface [%s] component in %d!\n",name, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((component = NFobjListFindItemByName (list,attrib)) == (NFobject_p) NULL) {
		CMmsgPrint (CMmsgUsrError, "Invalid interface [%s] component [%s] in line %d!\n",name, attrib, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((attrib = NFparseGetAttribute (attr, NFnumVariableStr, (char *) NULL)) == (char *) NULL) {
		CMmsgPrint (CMmsgUsrError, "Missing interface [%s] variable in line %d!\n",name,XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	switch (component->Type) {
	case NFcompAggregate: inputVar = (NFnumVariable_p) NFobjListFindItemByName (((NFcompAggregate_p) component)->Variables,attrib); break;
	case NFcompInput:     inputVar = (NFnumVariable_p) NFobjListFindItemByName (((NFcompInput_p    ) component)->Variables,attrib); break;
	case NFcompContainer: inputVar = (NFnumVariable_p) NFobjListFindItemByName (((NFcompContainer_p) component)->Variables,attrib); break;
	default:
		CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__);
		goto Abort;
	}
	if (inputVar == (NFnumVariable_p) NULL) {
		CMmsgPrint (CMmsgUsrError, "Missing interface [%s] variable [%s] in line %d!\n",name, attrib, XML_GetCurrentLineNumber (parser));
		goto Abort;
	}
	if ((module    = (NFmodInterface_p) NFobjectCreate (name,NFmodInterface)) == (NFmodInterface_p) NULL) {
		CMmsgPrint (CMmsgAppError, "Interface module creation error in %s:%d.\n",__FILE__,__LINE__);
		goto Abort;
	}
	if ((module->Variable = (NFnumVariable_p) NFobjectCreate (name,NFnumVariable))  == (NFnumVariable_p) NULL) {
		CMmsgPrint (CMmsgAppError, "Derivative variable creation error in %s:%d.\n",__FILE__,__LINE__);
		goto Abort;
	}
	if ((attrib = NFparseGetAttribute (attr, NFattrCouplerStr, (char *) NULL)) != (char *) NULL) {
		if      (strcmp (attrib,NFkeyCouplerFluxStr)  == 0) module->CouplerType = NFcouplerFlux;
		else if (strcmp (attrib,NFkeyCouplerPointStr) == 0) module->CouplerType = NFcouplerPoint;
		else if (strcmp (attrib,NFkeyCouplerSurfStr)  == 0) module->CouplerType = NFcouplerSurface;
		// TODO set interface weight when the coupler type is point!
	}
	module->Component = (NFcomponent_p) component;
	module->Variable->Parent  = (NFobject_p) module;
	module->Variable->StandardName = CMstrDuplicate (inputVar->StandardName);
	module->Variable->UnitString   = CMstrDuplicate (inputVar->UnitString);

	module->InputVar   = inputVar;

	module->Parent = parent;
	return ((NFobject_p) module);
Abort:
	if (module           != (NFmodInterface_p) NULL) {
		if (module->Variable != (NFnumVariable_p) NULL)
			NFobjectFree ((NFobject_p) module->Variable);
		NFobjectFree ((NFobject_p) module);
	}
	return ((NFobject_p) NULL);
}