Skip to content

Commit

Permalink
Clean algebraic vectors and use discretes in DH matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinffernandez committed Apr 21, 2023
1 parent 9e6aee4 commit 24ddc51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/mmoc/generator/model_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ void ModelInstance::freeVector(string name, int size) const

void ModelInstance::allocateVectors() const
{
allocateVector("algebraics", _model.algebraicNbr());
allocateVector("states", _model.stateNbr());
allocateVector("discretes", _model.discreteNbr());
allocateVector("events", _model.eventNbr());
Expand All @@ -432,6 +433,7 @@ void ModelInstance::allocateVectors() const

void ModelInstance::freeVectors() const
{
freeVector("algebraics", _model.algebraicNbr());
freeVector("states", _model.stateNbr());
freeVector("discretes", _model.discreteNbr());
freeVector("events", _model.eventNbr());
Expand Down Expand Up @@ -588,7 +590,7 @@ void QSSModelInstance::initializeDataStructures()
inputs();

// Initialize Jacobian matrices.
initializeMatrix(deps.JAC(), WRITER::Alloc_Data, WRITER::Init_Data, _model.stateNbr());
initializeMatrix(deps.JAC(), WRITER::Alloc_Data, WRITER::Init_Data, 0);

// Initialize Event Data Structures.
initializeMatrix(deps.SZ(), WRITER::Alloc_Data, WRITER::Init_Data, _model.stateNbr());
Expand All @@ -600,7 +602,7 @@ void QSSModelInstance::initializeDataStructures()
initializeMatrix(deps.LHSSt(), WRITER::Alloc_Data, WRITER::Init_Data, _model.eventNbr());
initializeMatrix(deps.RHSSt(), WRITER::Alloc_Data, WRITER::Init_Data, _model.eventNbr());
if (PARALLEL) {
initializeMatrix(deps.DH(), WRITER::Alloc_Data, WRITER::Init_Data, _model.eventNbr());
initializeMatrix(deps.DH(), WRITER::Alloc_Data, WRITER::Init_Data, _model.discreteNbr());
initializeMatrix(deps.SH(), WRITER::Alloc_Data, WRITER::Init_Data, _model.stateNbr());
initializeMatrix(deps.HH(), WRITER::Alloc_Data, WRITER::Init_Data, _model.eventNbr());
}
Expand Down
24 changes: 11 additions & 13 deletions src/mmoc/generator/model_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
******************************************************************************/

#ifndef MMO_MODEL_INSTANCE_H_
#define MMO_MODEL_INSTANCE_H_
#pragma once

#include <boost/variant/variant.hpp>
#include <sstream>

#include "../ir/class.h"
#include "../util/compile_flags.h"
#include "../util/graph.h"
#include <generator/writer.h>
#include <ir/class.h>
#include <util/compile_flags.h>
#include <util/graph.h>
#include <util/model_config.h>
#include "../util/symbol_table.h"
#include "../util/util_types.h"
#include "writer.h"
#include <util/symbol_table.h>
#include <util/util_types.h>

namespace MicroModelica {
namespace Generator {
Expand Down Expand Up @@ -86,15 +85,16 @@ class ModelInstance {
void initializeMatrix(DM vdm, WRITER::Section alloc, WRITER::Section init, int size)
{
_writer->write(vdm.alloc(), alloc);
if (!vdm.empty()) {
if (!vdm.empty() && size > 0) {
std::stringstream buffer;
buffer << "cleanVector(" << vdm.accessVector() << ", 0, " << size << ");";
_writer->write(buffer.str(), init);
}
_writer->write(vdm.init(), init);
}
template<class Builder>
void generateDef(IR::EquationTable eqs, WRITER::Section model_def, WRITER::Section simple, WRITER::Section generic) {
template <class Builder>
void generateDef(IR::EquationTable eqs, WRITER::Section model_def, WRITER::Section simple, WRITER::Section generic)
{
Builder model;
Util::ModelConfig::instance().clearLocalSymbols();
IR::FunctionPrinter printer;
Expand All @@ -108,7 +108,6 @@ class ModelInstance {
}
}


private:
IR::Model _model;
Util::CompileFlags _flags;
Expand Down Expand Up @@ -163,4 +162,3 @@ class ClassicModelInstance : public ModelInstance {
typedef std::shared_ptr<ModelInstance> ModelInstancePtr;
} // namespace Generator
} // namespace MicroModelica
#endif /* MMO_MODEL_INSTANCE_H */

0 comments on commit 24ddc51

Please sign in to comment.