Skip to content

Commit

Permalink
Renamed getSystemMatrix, getSystemSparseMatrix and getRHS in ILinearA…
Browse files Browse the repository at this point in the history
…lgloop.h to getAMatrix, getSparseAMatrix and getb.
  • Loading branch information
qichenghua authored and OpenModelica-Hudson committed Jan 12, 2017
1 parent a70aefe commit a558ce2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
32 changes: 19 additions & 13 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -6110,12 +6110,12 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
end match
<<

const matrix_t& <%modelName%>Algloop<%ls.index%>::getSystemMatrix()
const matrix_t& <%modelName%>Algloop<%ls.index%>::getAMatrix()
{
<%getDenseMatrix%>
}

sparsematrix_t& <%modelName%>Algloop<%ls.index%>::getSystemSparseMatrix( )
sparsematrix_t& <%modelName%>Algloop<%ls.index%>::getSparseAMatrix( )
{
<%getSparseMatrix%>
}
Expand All @@ -6139,12 +6139,12 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
end match
<<

const matrix_t& <%modelName%>Algloop<%ls.index%>::getSystemMatrix()
const matrix_t& <%modelName%>Algloop<%ls.index%>::getAMatrix()
{
<%getDenseMatrix%>
}

sparsematrix_t& <%modelName%>Algloop<%ls.index%>::getSystemSparseMatrix()
sparsematrix_t& <%modelName%>Algloop<%ls.index%>::getSparseAMatrix()
{
<%getSparseMatrix%>
}
Expand Down Expand Up @@ -6175,15 +6175,15 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
match ls.jacobianMatrix
case SOME(__) then
<<
void <%modelname%>Algloop<%ls.index%>::getRHS(double* residuals) const
void <%modelname%>Algloop<%ls.index%>::getb(double* residuals) const
{
LinearAlgLoopDefaultImplementation::getRHS(residuals);
LinearAlgLoopDefaultImplementation::getb(residuals);
}

>>
else
<<
void <%modelname%>Algloop<%ls.index%>::getRHS(double* residuals) const
void <%modelname%>Algloop<%ls.index%>::getb(double* residuals) const
{
memcpy(residuals,__b.getData(),sizeof(double)* _dimAEq);
}
Expand All @@ -6198,7 +6198,7 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
match eq
case SES_LINEAR(lSystem = ls as LINEARSYSTEM(__)) then
<<
void <%modelname%>Algloop<%ls.index%>::getRHS(double* vars) const
void <%modelname%>Algloop<%ls.index%>::getb(double* vars) const
{
ublas::matrix<double> A=toMatrix(_dimAEq,_dimAEq,__A->data());
double* doubleUnknowns = new double[_dimAEq];
Expand Down Expand Up @@ -6666,7 +6666,7 @@ template writeoutputAlgloopsolvers(SimEqSystem eq, SimCode simCode ,Text& extraF
case SIMCODE(modelInfo = MODELINFO(__)) then
<<
double* doubleResiduals<%num%> = new double[_algLoop<%num%>->getDimReal()];
_algLoop<%num%>->getRHS(doubleResiduals<%num%>);
_algLoop<%num%>->getb(doubleResiduals<%num%>);

>>
end match
Expand Down Expand Up @@ -7031,6 +7031,11 @@ case SIMCODE(modelInfo = MODELINFO(__)) then

<%generateAlgloopMethodDeclarationCode(simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace)%>

/// Provide the right hand side (residuals)
virtual void getb(double* vars) const;
virtual const matrix_t& getAMatrix() ;
virtual sparsematrix_t& getSparseAMatrix() ;

bool getUseSparseFormat();

void setUseSparseFormat(bool value);
Expand Down Expand Up @@ -7062,6 +7067,11 @@ case SIMCODE(modelInfo = MODELINFO(__)) then

<%generateAlgloopMethodDeclarationCode(simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace)%>

/// Provide the right hand side (residuals)
virtual void getRHS(double* vars) const;
virtual const matrix_t& getSystemMatrix() ;
virtual sparsematrix_t& getSystemSparseMatrix() ;

bool getUseSparseFormat();
void setUseSparseFormat(bool value);
float queryDensity();
Expand Down Expand Up @@ -7629,17 +7639,13 @@ case SIMCODE(modelInfo = MODELINFO(__)) then

/// Evaluate equations for given variables
virtual void evaluate();
/// Provide the right hand side (residuals)
virtual void getRHS(double* vars) const;
<%if Flags.isSet(Flags.WRITE_TO_BUFFER) then
<<
/// Provide dimensions of residuals for linear equation systems
virtual int giveDimResiduals(int index);
/// Provide the residuals for linear equation systems
virtual void giveResiduals(double* vars);
>>%>
virtual const matrix_t& getSystemMatrix() ;
virtual sparsematrix_t& getSystemSparseMatrix() ;
virtual bool isLinearTearing();
virtual bool isConsistent();

Expand Down
Expand Up @@ -39,7 +39,7 @@ void LinearAlgLoopDefaultImplementation::initialize()
memset(_b,0,_dimAEq*sizeof(double));
};

void LinearAlgLoopDefaultImplementation::getRHS(double* res) const
void LinearAlgLoopDefaultImplementation::getb(double* res) const
{
memcpy(res, _b, sizeof(double) * _dimAEq);
}
Expand Down
8 changes: 4 additions & 4 deletions SimulationRuntime/cpp/Include/Core/System/ILinearAlgLoop.h
Expand Up @@ -52,13 +52,13 @@ class ILinearAlgLoop
/// Evaluate equations for given variables
virtual void evaluate() = 0;

/// Provide the right hand side (residuals)
virtual void getRHS(double* res) const = 0;
/// Provide the right hand side (b-vector)
virtual void getb(double* res) const = 0;

//testing commenting out virtual void getSparseAdata(double* data, int nonzeros) = 0;

virtual const matrix_t& getSystemMatrix() = 0;
virtual sparsematrix_t& getSystemSparseMatrix() = 0;
virtual const matrix_t& getAMatrix() = 0;
virtual sparsematrix_t& getSparseAMatrix() = 0;
virtual bool isLinearTearing() = 0;
virtual bool isConsistent() = 0;
virtual bool getUseSparseFormat() = 0;
Expand Down
Expand Up @@ -32,7 +32,7 @@ class BOOST_EXTENSION_ALGLOOPDEFAULTIMPL_DECL LinearAlgLoopDefaultImplementation
void initialize();

/// Provide the right hand side (residuals)
void getRHS(double* res) const;
void getb(double* res) const;

bool getUseSparseFormat();

Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Solver/Dgesv/DgesvSolver.cpp
Expand Up @@ -113,9 +113,9 @@ void DgesvSolver::solve()
_algLoop->setReal(_zeroVec); //if the system is linear Tearing it means that the system is of the form Ax-b=0, so plugging in x=0 yields -b for the left hand side

_algLoop->evaluate();
_algLoop->getRHS(_b);
_algLoop->getb(_b);

const matrix_t& A = _algLoop->getSystemMatrix();
const matrix_t& A = _algLoop->getAMatrix();
const double* Atemp = A.data().begin();

memcpy(_A, Atemp, _dimSys*_dimSys*sizeof(double));
Expand Down
10 changes: 5 additions & 5 deletions SimulationRuntime/cpp/Solver/LinearSolver/LinearSolver.cpp
Expand Up @@ -138,7 +138,7 @@ void LinearSolver::initialize()
ok=klu_defaults (_kluCommon);
if (ok!=1) throw ModelicaSimulationError(ALGLOOP_SOLVER,"error initializing Sparse Solver KLU");

sparsematrix_t& A = _algLoop->getSystemSparseMatrix();
sparsematrix_t& A = _algLoop->getSparseAMatrix();

_nonzeros = A.nnz();

Expand Down Expand Up @@ -194,10 +194,10 @@ void LinearSolver::solve()
_algLoop->setReal(_zeroVec); //if the system is linear Tearing it means that the system is of the form Ax-b=0, so plugging in x=0 yields -b for the left hand side

_algLoop->evaluate();
_algLoop->getRHS(_b);
_algLoop->getb(_b);

if (_sparse == false){
const matrix_t& A = _algLoop->getSystemMatrix();
const matrix_t& A = _algLoop->getAMatrix();
const double* Atemp = A.data().begin();

memcpy(_A, Atemp, _dimSys*_dimSys*sizeof(double));
Expand Down Expand Up @@ -240,7 +240,7 @@ void LinearSolver::solve()
/*this version is a test. it extracts the dense format out of the sparse format and uses the dense lapack solver to sove the dense problem.
//writing entries of A
sparsematrix_t& A = _algLoop->getSystemSparseMatrix();
sparsematrix_t& A = _algLoop->getSparseAMatrix();
_Ax= boost::numeric::bindings::begin_value (A);
Expand Down Expand Up @@ -346,7 +346,7 @@ void LinearSolver::solve()


//writing entries of A
sparsematrix_t& A = _algLoop->getSystemSparseMatrix();
sparsematrix_t& A = _algLoop->getSparseAMatrix();
_Ax= boost::numeric::bindings::begin_value (A);

int ok = klu_refactor (_Ap, _Ai, _Ax, _kluSymbolic, _kluNumeric, _kluCommon) ;
Expand Down
8 changes: 4 additions & 4 deletions SimulationRuntime/cpp/Solver/UmfPack/UmfPack.cpp
Expand Up @@ -55,9 +55,9 @@ void UmfPack::solve()
long int irtrn = 0; // Retrun-flag of Fortran code _algLoop->getReal(_y);
long int * _helpArray = new long int[_algLoop->getDimReal()];
_algLoop->evaluate();
_algLoop->getRHS(_rhs);
_algLoop->getb(_rhs);

const matrix_t& A = _algLoop->getSystemMatrix();
const matrix_t& A = _algLoop->getAMatrix();
const double* jacd = A.data().begin();
memcpy(_jacd, jacd, dimSys*dimSys*sizeof(double));

Expand All @@ -77,9 +77,9 @@ void UmfPack::solve()
Control [UMFPACK_PRL] = 6;

_algLoop->evaluate();
_algLoop->getRHS(_rhs);
_algLoop->getb(_rhs);
long int dimSys = _algLoop->getDimReal();
const sparsematrix_t& A = _algLoop->getSystemSparseMatrix();
const sparsematrix_t& A = _algLoop->getSparseAMatrix();

adaptor_t rhs_adaptor(dimSys,_rhs);
shared_vector_t b(dimSys,rhs_adaptor);
Expand Down

0 comments on commit a558ce2

Please sign in to comment.