/*! \fn updateInitialGuessDB
 *
 *  This function writes new values to solution list.
 *
 *  \param [in]  [nonlinsys]
 *  \param [in]  [time] time for extrapolation
 *  \param [in]  [context] current context of evaluation
 *
 */
int updateInitialGuessDB(NONLINEAR_SYSTEM_DATA *nonlinsys, double time, int context)
{
  /* write solution to oldValue list for extrapolation */
  if (nonlinsys->solved == 1)
  {
    /* do not use solution of jacobian for next extrapolation */
    if (context < 4)
    {
      addListElement((VALUES_LIST*)nonlinsys->oldValueList,
              createValueElement(nonlinsys->size, time, nonlinsys->nlsx));
    }
  }
  else if (nonlinsys->solved == 2)
  {
    if (listLen(((VALUES_LIST*)nonlinsys->oldValueList)->valueList)>0)
    {
      cleanValueList((VALUES_LIST*)nonlinsys->oldValueList, NULL);
    }
    /* do not use solution of jacobian for next extrapolation */
    if (context < 4)
    {
      addListElement((VALUES_LIST*)nonlinsys->oldValueList,
              createValueElement(nonlinsys->size, time, nonlinsys->nlsx));
    }
  }
  messageClose(LOG_NLS_EXTRAPOLATE);
  return 0;
}
Exemple #2
0
Column::AST* Column::createOperationElement(pugi::xml_node operation, const pugi::xml_document &doc)
{

	AST *ast = new AST;
	pugi::xpath_node arg1, arg2;
	std::string type;
	std::stringstream ss;

	/* set type and operation */
	ast->type = fbitdump::Column::AST::operationType;
	ast->operation = operation.attribute("name").value()[0];
	ast->semantics = operation.attribute("semantics").value();

	/* get argument nodes */
	arg1 = doc.select_single_node(("/configuration/columns/column[alias='"+ std::string(operation.child_value("arg1"))+ "']").c_str());
	arg2 = doc.select_single_node(("/configuration/columns/column[alias='"+ std::string(operation.child_value("arg2"))+ "']").c_str());

	/* get argument type */
	type = arg1.node().child("value").attribute("type").value();

	this->element += "( ";

	/* add argument to AST */
	if (type == "operation") {
		ast->left = createOperationElement(arg1.node().child("value").child("operation"), doc);
	} else if (type == "plain"){
		ast->left = createValueElement(arg1.node().child("value").child("element"), doc);
		this->element += ast->left->value;
	} else {
		std::cerr << "Value of type operation contains node of type " << type << std::endl;
	}

	ss << " " << ast->operation << " ";
	this->element += ss.str();

	/* same for the second argument */
	type = arg2.node().child("value").attribute("type").value();

	if (type == "operation") {
		ast->right = createOperationElement(arg2.node().child("value").child("operation"), doc);
	} else if (type == "plain"){
		ast->right = createValueElement(arg2.node().child("value").child("element"), doc);
		this->element += ast->right->value;
	} else {
		std::cerr << "Value of type operation contains node of type '" << type << "'" << std::endl;
	}

	this->element += " )";
	return ast;
}
Exemple #3
0
Column::AST* Column::createValueElement(pugi::xml_node element, const pugi::xml_document &doc)
{

	/* when we have alias, go down one level */
	if (element.child_value()[0] == '%') {
		pugi::xpath_node el = doc.select_single_node(
				("/configuration/columns/column[alias='"
						+ std::string(element.child_value())
						+ "']/value/element").c_str());
		return createValueElement(el.node(), doc);
	}

	/* create the element */
	AST *ast = new AST;

	ast->type = fbitdump::Column::AST::valueType;
	ast->value = element.child_value();
	ast->semantics = element.attribute("semantics").value();
	if (element.attribute("parts")) {
		ast->parts = atoi(element.attribute("parts").value());
	}
	if (element.attribute("aggregation")) {
		ast->aggregation = element.attribute("aggregation").value();
	}

	return ast;
}
Exemple #4
0
void Column::init(const pugi::xml_document &doc, const std::string &alias, bool aggregate) throw(std::invalid_argument)
{
	this->format = NULL;
	this->parse = NULL;

	/* search xml for an alias */
	pugi::xpath_node column = doc.select_single_node(("/configuration/columns/column[alias='"+alias+"']").c_str());
	/* check what we found */
	if (column == NULL) {
		throw std::invalid_argument(std::string("Column '") + alias + "' not defined");
	}

	/* set default value */
	if (column.node().child("default-value") != NULL) {
		this->nullStr = column.node().child_value("default-value");
	}

	this->setName(column.node().child_value("name"));
	this->setAggregation(aggregate);

#ifdef DEBUG
	std::cerr << "Creating column '" << this->name << "'" << std::endl;
#endif

	/* set alignment */
	if (column.node().child("alignLeft") != NULL) {
		this->setAlignLeft(true);
	}

	/* set width */
	if (column.node().child("width") != NULL) {
		this->setWidth(atoi(column.node().child_value("width")));
	}

	/* set value according to type */
	if (column.node().child("value").attribute("type").value() == std::string("plain")) {
		/* simple element */
		this->setAST(createValueElement(column.node().child("value").child("element"), doc));
	} else if (column.node().child("value").attribute("type").value() == std::string("operation")) {
		/* operation */
		this->setAST(createOperationElement(column.node().child("value").child("operation"), doc));
	}

	/* add aliases from XML to column (with starting %) */
	pugi::xpath_node_set aliases = column.node().select_nodes("alias");
	for (pugi::xpath_node_set::const_iterator it = aliases.begin(); it != aliases.end(); ++it) {
		this->addAlias(it->node().child_value());
	}

	/* element is name of the file, which contains actual data for this column */
	if (column.node().child("value").child("element") != 0) {
		this->element = column.node().child("value").child_value("element");
	}

	/* check whether this is a summary column */
	pugi::xpath_node_set sumColumns = doc.select_nodes("/configuration/summary/column");
	for (stringSet::const_iterator it = this->aliases.begin(); it != this->aliases.end(); it++) {
		for (pugi::xpath_node_set::const_iterator i = sumColumns.begin(); i != sumColumns.end(); ++i) {
			if (*it == i->node().child_value()) {
				this->summary = true;
			
				if (!i->node().attribute("type")) {
					throw std::invalid_argument("Summary column '" + alias + "' without specified summary type!");
				}

				this->summaryType = i->node().attribute("type").value();
			}
		}
	}
	
	/* set alias for select clause */
	if (this->getSemantics() == "flows") {
		this->selectName = "flows";
	} else if (this->isOperation()) {
		this->selectName = alias.substr(1);
	} else {
		this->selectName = this->element;
	}
}