Skip to content

Commit

Permalink
fixes bug with sparse_matrix type
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21379 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Michael Kloeppel committed Jul 1, 2014
1 parent 406ecfb commit 516d80e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
12 changes: 8 additions & 4 deletions SimulationRuntime/cpp/Include/Core/Math/SparseMatrix.h
@@ -1,10 +1,7 @@
#pragma once

//#include <map>
//#include <vector>
#include "Modelica.h"
//#include <stdexcept>

#include "Modelica.h"
#ifdef USE_UMFPACK
#include "umfpack.h"

Expand Down Expand Up @@ -52,5 +49,12 @@ struct sparse_matrix {
void build(sparse_inserter& ins);
int solve(const double* b,double* x);
};
#else
struct sparse_inserter {
};

struct sparse_matrix {
void build(sparse_inserter& ins);
int solve(const double* b,double* x);
};
#endif
35 changes: 6 additions & 29 deletions SimulationRuntime/cpp/Solver/UmfPack/UmfPack.cpp
Expand Up @@ -4,10 +4,6 @@

UmfPack::UmfPack(IAlgLoop* algLoop, ILinSolverSettings* settings) : _iterationStatus(CONTINUE), _umfpackSettings(settings), _algLoop(algLoop), _jac(NULL), _rhs(NULL)
{
ofstream file;
file.open("umfpack.out",ios::app);
file<<"constructor"<<std::endl;
file.close();
}

UmfPack::~UmfPack() {
Expand All @@ -18,48 +14,29 @@ UmfPack::~UmfPack() {

void UmfPack::initialize()
{

#ifdef USE_UMFPACK
_algLoop->setUseSparseFormat(_umfpackSettings->getUseSparseFormat());
_algLoop->initialize();
_jac = new sparse_matrix;
_rhs = new double[_algLoop->getDimReal()];
_x = new double[_algLoop->getDimReal()];
ofstream file;
file.open("umfpack.out",ios::app);
file<<"init"<<std::endl;
file.close();
#endif
}

void UmfPack::solve()
{
ofstream file;
file.open("umfpack.out",ios::app);
_algLoop->evaluate();
file<<"evaluate"<<std::endl;
_algLoop->getRHS(_rhs);
file<<"getrhs"<<std::endl;
#ifdef USE_UMFPACK

_algLoop->getSystemMatrix(_jac);
file<<"_jac"<<std::endl;
for(std::vector<int>::iterator it=_jac->Ap.begin(); it!=_jac->Ap.end(); it++) {
file<<*it<<" ";
}
file<<std::endl;
for(std::vector<int>::iterator it=_jac->Ai.begin(); it!=_jac->Ai.end(); it++) {
file<<*it<<" ";
}
file<<std::endl;
for(std::vector<double>::iterator it=_jac->Ax.begin(); it!=_jac->Ax.end(); it++) {
file<<*it<<" ";
}
file<<std::endl;
file.close();

int status=_jac->solve(_rhs,_x);
if(status==0) {
_iterationStatus=DONE;
} else {
_iterationStatus=SOLVERERROR;
}
_algLoop->setReal(_x);
#endif
}

IAlgLoopSolver::ITERATIONSTATUS UmfPack::getIterationStatus()
Expand Down

0 comments on commit 516d80e

Please sign in to comment.