Skip to content

Commit

Permalink
[Cpp] Fix derivative vars in XmlPropertyReader, ticket:4773
Browse files Browse the repository at this point in the history
Commit b528b72
(Fatemeh Davoudi implementation of the symbolic model reduction algorithm)
introduced _derVars and _resVars along with a second constructor that
initialized the dimension of _derVars as _dimRHS. This second constructor
was not used though, leaving _dimRHS undefined and running a for loop with
undefined end during initialization.

This commit removes the second constructor and the uninitialized variable.
It uses consistent size info from SimVars instead.

Belonging to [master]:
  - OpenModelica/OMCompiler#2805
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Dec 2, 2018
1 parent 6f93d97 commit 9bcafd6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
22 changes: 7 additions & 15 deletions SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
Expand Up @@ -16,14 +16,6 @@ XmlPropertyReader::XmlPropertyReader(IGlobalSettings *globalSettings, std::strin
,_isInitialized(false)
{
}
XmlPropertyReader::XmlPropertyReader(IGlobalSettings *globalSettings, std::string propertyFile,int dimRHS)
: IPropertyReader()
,_globalSettings(globalSettings)
,_propertyFile(propertyFile)
,_isInitialized(false)
,_dimRHS(dimRHS)
{
}
XmlPropertyReader::~XmlPropertyReader()
{
}
Expand Down Expand Up @@ -173,13 +165,13 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
}
}

int derSize=_dimRHS;
for(int i=0; i<derSize;i++)
{
string name="der";
string descripton="der";
_derVars.addOutputVar(name, descripton, derVars+i, false);
}
size_t derSize = sim_vars->getDimStateVars();
string name = "der";
string descripton = "der";
for (size_t i = 0; i < derSize; i++)
{
_derVars.addOutputVar(name, descripton, derVars + i, false);
}

LOGGER_WRITE_END(LC_INIT, LL_DEBUG);
}
Expand Down
Expand Up @@ -7,7 +7,6 @@ class BOOST_EXTENSION_XML_READER_DECL XmlPropertyReader : public IPropertyReader
{
public:
XmlPropertyReader(IGlobalSettings *globalSettings, std::string propertyFile);
XmlPropertyReader(IGlobalSettings *globalSettings, std::string propertyFile, int dimRHS);
~XmlPropertyReader();

void readInitialValues(IContinuous& system, shared_ptr<ISimVars> sim_vars);
Expand All @@ -28,6 +27,5 @@ class BOOST_EXTENSION_XML_READER_DECL XmlPropertyReader : public IPropertyReader
output_real_vars_t _realVars;
output_der_vars_t _derVars;
output_res_vars_t _resVars;
int _dimRHS;
bool _isInitialized;
};
8 changes: 8 additions & 0 deletions SimulationRuntime/cpp/Include/Core/System/ISimVars.h
Expand Up @@ -27,6 +27,14 @@ class ISimVars
virtual void setBoolVarsVector(const bool* vars) = 0;
virtual void setStringVarsVector(const string* vars) = 0;

/*Methods to get sizes of variable vectors*/
virtual size_t getDimString() const = 0;
virtual size_t getDimBool() const = 0;
virtual size_t getDimInt() const = 0;
virtual size_t getDimPreVars() const = 0;
virtual size_t getDimReal() const = 0;
virtual size_t getDimStateVars() const = 0;
virtual size_t getStateVectorIndex() const = 0;

/*Methods for initialize model array variables in simvars memory*/
virtual double* initRealArrayVar(size_t size,size_t start_index)= 0;
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/cpp/Include/Core/System/SimVars.h
Expand Up @@ -111,9 +111,6 @@ class BOOST_EXTENSION_SIMVARS_DECL SimVars: public ISimVars
virtual int& getPreVar(const int& var);
virtual bool& getPreVar(const bool& var);

protected:
void create(size_t dim_real, size_t dim_int, size_t dim_bool, size_t dim_string, size_t dim_pre_vars, size_t dim_state_vars, size_t state_index);

virtual size_t getDimString() const;
virtual size_t getDimBool() const;
virtual size_t getDimInt() const;
Expand All @@ -122,6 +119,9 @@ class BOOST_EXTENSION_SIMVARS_DECL SimVars: public ISimVars
virtual size_t getDimStateVars() const;
virtual size_t getStateVectorIndex() const;

protected:
void create(size_t dim_real, size_t dim_int, size_t dim_bool, size_t dim_string, size_t dim_pre_vars, size_t dim_state_vars, size_t state_index);

void *alignedMalloc(size_t required_bytes, size_t alignment);
void alignedFree(void* p);

Expand Down

0 comments on commit 9bcafd6

Please sign in to comment.