Skip to content

Commit

Permalink
enum added
Browse files Browse the repository at this point in the history
  • Loading branch information
devyeshtandon committed Aug 12, 2016
1 parent 57fdb7d commit fbe0f57
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 44 deletions.
22 changes: 11 additions & 11 deletions mbdynFMI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ void fmu2::setCallBackFunction(){

void fmu2::ImportCreateDLL(){

if(simType == 1){
if(simType == IMPORT){
jmstatus = fmi2_import_create_dllfmu(fmu, fmi2_fmu_kind_me, &callBackFunctions);
}
else if (simType == 0){
else if (simType == COSIM){
jmstatus = fmi2_import_create_dllfmu(fmu, fmi2_fmu_kind_cs, &callBackFunctions);
}
else{
Expand Down Expand Up @@ -176,10 +176,10 @@ void fmu2::Initialize(double dTol, double time, double rTol){
bool fmu2::SupportsDirectionalDerivatives(){
unsigned int capability;

if(simType == 0){
if(simType == COSIM){
fmi2_capabilities_enu_t id = fmi2_cs_providesDirectionalDerivatives;
capability = fmi2_xml_get_capability(fmu->md, id);
} else if (simType == 1){
} else if (simType == IMPORT){
fmi2_capabilities_enu_t id = fmi2_me_providesDirectionalDerivatives;
capability = fmi2_xml_get_capability(fmu->md, id);
}
Expand All @@ -195,7 +195,7 @@ bool fmu2::SupportsDirectionalDerivatives(){

}

void fmu2::GetDirectionalDerivatives(FullMatrixHandler jacobian, int* inputStatesVRef, int inputLength, double* seedVector){
void fmu2::GetDirectionalDerivatives(FullMatrixHandler* jacobian, int* inputStatesVRef, int inputLength, double* seedVector){
//Seed Vector (the state value)

fmi2_import_variable_list_t* derivativeList = fmi2_import_get_derivatives_list(fmu);
Expand Down Expand Up @@ -224,7 +224,7 @@ void fmu2::GetDirectionalDerivatives(FullMatrixHandler jacobian, int* inputState
STATUSCHECK(fmistatus);

for (int j=0; j<numOfContStates + inputLength; j++){
jacobian.PutCoef(i,j,output[j]);
jacobian->PutCoef(i+1, j+1, output[j]);
}
}
delete[] derList;
Expand Down Expand Up @@ -290,12 +290,12 @@ double fmu2::GetStateFromRefValue(unsigned int i){
}

fmu2::~fmu2(void){
delete[] eventIndicators;
delete[] eventIndicatorsPrev;
// delete[] eventIndicators;
// delete[] eventIndicatorsPrev;

fmi_import_free_context(context);

if (simType ==1 ){
if (simType == IMPORT ){

fmi2_import_free_instance(fmu);
fmi2_import_free(fmu);
Expand Down Expand Up @@ -425,7 +425,7 @@ fmu::~fmu(void){
fmu1::~fmu1(void){
fmi_xml_free_context(context);

if(simType == 1){
if(simType == IMPORT){

fmi1_capi_free_dll(fmu->capi);

Expand Down Expand Up @@ -635,7 +635,7 @@ bool fmu1::SupportsDirectionalDerivatives(){
return false;
}

void fmu1::GetDirectionalDerivatives(FullMatrixHandler jacobian, int* vector, int vectorLength, double* seedVector){
void fmu1::GetDirectionalDerivatives(FullMatrixHandler* jacobian, int* vector, int vectorLength, double* seedVector){
NO_OP;
}

Expand Down
37 changes: 22 additions & 15 deletions mbdynFMI.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@

class fmu {
public:
enum SimulationTypes{
COSIM,
IMPORT
};

int simType;
fmi_import_context_t* context;

fmu(fmi_import_context_t* text, int type){
context = text;
simType = type;
}

virtual void parseXML(fmi_import_context_t* context, const char* dirPath) = 0;
virtual void setCallBackFunction() = 0;

Expand All @@ -56,7 +69,7 @@ class fmu {
virtual double GetStateFromRefValue(unsigned int i) = 0;
virtual void GetStateDerivatives(double*) = 0;
virtual void GetStates(double*) = 0;
virtual void GetDirectionalDerivatives(FullMatrixHandler ,int*, int, double *) = 0;
virtual void GetDirectionalDerivatives(FullMatrixHandler *,int*, int, double *) = 0;
virtual bool SupportsDirectionalDerivatives() = 0;

virtual bool CheckInterrupts(double, double*) = 0;
Expand All @@ -74,8 +87,7 @@ class fmu1 :public fmu{
fmi1_import_t* fmu;

fmi1_status_t fmistatus;
jm_status_enu_t jmstatus;
fmi_import_context_t* context;
jm_status_enu_t jmstatus;

fmi1_real_t currTime;
fmi1_real_t relativeTolerance;
Expand All @@ -93,14 +105,12 @@ class fmu1 :public fmu{
fmi1_boolean_t intermediateResults;
fmi1_import_variable_list_t* vl;

int simType; //1: IMPORT 2:COSIM
public:
void parseXML(fmi_import_context_t* context, const char* dirPath);
void setCallBackFunction();

fmu1(fmi_import_context_t* text, int type){
context = text;
simType = type;
fmu1(fmi_import_context_t* text, int type):fmu::fmu(text, type){
NO_OP;
}

void ImportCreateDLL(void);
Expand All @@ -123,7 +133,7 @@ class fmu1 :public fmu{
double GetStateFromRefValue(unsigned int i);
void GetStateDerivatives(double*);
void GetStates(double *);
void GetDirectionalDerivatives(FullMatrixHandler, int*, int, double*);
void GetDirectionalDerivatives(FullMatrixHandler *, int*, int, double*);
bool SupportsDirectionalDerivatives();

bool CheckInterrupts(double, double*);
Expand All @@ -142,7 +152,7 @@ class fmu2 : public fmu{

fmi2_status_t fmistatus;
jm_status_enu_t jmstatus;
fmi_import_context_t* context;


fmi2_real_t currTime;
fmi2_real_t relativeTolerance;
Expand All @@ -161,15 +171,12 @@ class fmu2 : public fmu{
fmi2_boolean_t intermediateResults;
fmi2_import_variable_list_t* vl;

int simType; //1: IMPORT 2:COSIM

public:
void parseXML(fmi_import_context_t* context, const char* dirPath);
void setCallBackFunction();

fmu2(fmi_import_context_t* text, int type){
context= text;
simType = type;
fmu2(fmi_import_context_t* text, int type):fmu::fmu(text, type){
NO_OP;
}

void ImportCreateDLL(void);
Expand All @@ -192,7 +199,7 @@ class fmu2 : public fmu{
double GetStateFromRefValue(unsigned int i);
void GetStateDerivatives(double*);
void GetStates(double *);
void GetDirectionalDerivatives(FullMatrixHandler , int*, int, double*);
void GetDirectionalDerivatives(FullMatrixHandler *, int*, int, double*);
bool SupportsDirectionalDerivatives();

bool CheckInterrupts(double, double*);
Expand Down
Binary file modified mbdynFMI.o
Binary file not shown.
31 changes: 15 additions & 16 deletions module-FMU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pDM(pDM)

model->InitializeAsSlave(UClocation.c_str(), initialTime, endTime);
silent_cout("Initialized as slave\n");
timeStep = pDM->GetSolver()->GetDInitialTimeStep();
timeStep = pDM->GetSolver()->dGetInitialTimeStep();

}

Expand Down Expand Up @@ -155,9 +155,8 @@ pDM(pDM)
seedVector = new double[numOfContinousStates + privDriveLength];
}

Jacobian.Resize(numOfContinousStates,numOfContinousStates + privDriveLength);
Jacobian.Reset();

jacobian.Resize(numOfContinousStates,numOfContinousStates + privDriveLength);
jacobian.Reset();
}

ModuleFMU::~ModuleFMU(void)
Expand Down Expand Up @@ -237,7 +236,7 @@ ModuleFMU::AssJac(VariableSubMatrixHandler& WorkMat,
}

for (int j = 0; j <privDriveLength; j++){
WM.PutColIndex(i, privDrivesIndex[j]->iGetIndex());
WM.PutColIndex(i, privDrivesIndex[j]->iGetIndex()+1);
i++;
}
}
Expand All @@ -253,26 +252,26 @@ ModuleFMU::AssJac(VariableSubMatrixHandler& WorkMat,
seedVector[i+numOfContinousStates] = privDrivesIndex[i]->dGet();
}

model->GetDirectionalDerivatives(Jacobian, jacobianInputVector, privDriveLength, seedVector);
for (int i=0; i<numOfContinousStates; i++){
WM.IncCoef(i,i, 1);
for(int j=0; j<numOfContinousStates; j++){
WM.IncCoef(i,j, -dCoef*Jacobian.dGetCoef(i,j));
model->GetDirectionalDerivatives(&jacobian, jacobianInputVector, privDriveLength, seedVector);
for (int i=1; i<=numOfContinousStates; i++){
WM.IncCoef(i, i, 1);
for(int j=1; j<=numOfContinousStates; j++){
WM.IncCoef(i, j, -dCoef*jacobian.dGetCoef(i, j));
}

for(int j=numOfContinousStates; j<numOfContinousStates + privDriveLength; j++){
for(int j=numOfContinousStates+1; j<=numOfContinousStates + privDriveLength; j++){
if(privDrivesIndex[j-numOfContinousStates]->iGetSE()->
GetDofType(privDrivesIndex[i-numOfContinousStates]->iGetIndex())
GetDofType(privDrivesIndex[i-numOfContinousStates]->iGetIndex()+1)
== DofOrder::DIFFERENTIAL)
WM.IncCoef(i,j, -dCoef*Jacobian.dGetCoef(i,j));
WM.IncCoef(i, j, -dCoef*jacobian.dGetCoef(i, j));
else
WM.IncCoef(i,j, -Jacobian.dGetCoef(i,j));
WM.IncCoef(i, j, -jacobian.dGetCoef(i, j));
}
}

} else {
for(int i=1; i<=numOfContinousStates; i++){
WM.IncCoef(i , i, 1.);
WM.IncCoef(i, i, 1.);
}
}
}
Expand Down Expand Up @@ -316,7 +315,7 @@ ModuleFMU::AssRes(SubVectorHandler& WorkVec,
}

//Get Index of the elements
integer iFirstIndex = iGetFirstIndex();
integer iFirstIndex = iGetFirstIndex() + 1;

//Set Index to WorkVec
for (int i=1; i<=numOfContinousStates; i++){
Expand Down
3 changes: 1 addition & 2 deletions module-FMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ModuleFMU

jm_callbacks callbacks;
jm_status_enu_t status;


typedef std::map<std::string, const DriveCaller *> strDriveCon;
typedef std::map<int, const PrivDriveCaller*> intDriveCon;
Expand Down Expand Up @@ -101,6 +100,6 @@ class ModuleFMU
IMPORT
} SIMTYPE;

FullMatrixHandler Jacobian;
FullMatrixHandler jacobian;
};

Binary file modified module-FMU.o
Binary file not shown.

0 comments on commit fbe0f57

Please sign in to comment.