Skip to content

Commit 9118358

Browse files
committed
added default experiment and xml formatting
1 parent 60256d4 commit 9118358

5 files changed

Lines changed: 86 additions & 53 deletions

File tree

export/examples/VanDerPol/van_der_pol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ model_info fmu4cpp::get_model_info() {
8181
info.modelName = "VanDerPol";
8282
info.description = "VanDerPol oscillator";
8383
info.modelIdentifier = FMU4CPP_MODEL_IDENTIFIER;
84+
info.defaultExperiment = {0.0, 20};
8485
return info;
8586
}
8687

export/include/fmu4cpp/model_info.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
namespace fmu4cpp {
88

9+
struct default_experiment final {
10+
double startTime{0.0};
11+
std::optional<double> stopTime;
12+
std::optional<double> stepSize;
13+
std::optional<double> tolerance;
14+
};
15+
916
struct model_info final {
1017
std::string modelName;
1118
std::string author;
@@ -19,6 +26,8 @@ namespace fmu4cpp {
1926
bool canBeInstantiatedOnlyOncePerProcess{false};
2027
bool canGetAndSetFMUstate{false};
2128
bool canSerializeFMUstate{false};
29+
30+
std::optional<default_experiment> defaultExperiment;
2231
};
2332

2433
}// namespace fmu4cpp

export/src/fmu4cpp/fmi2/fmi2_description.cpp

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,48 @@ std::string fmu_base::make_description() const {
1212

1313
const model_info m = get_model_info();
1414
std::stringstream ss;
15-
ss << R"(<?xml version="1.0" encoding="UTF-8"?>)"
16-
<< "\n"
17-
<< R"(<fmiModelDescription fmiVersion="2.0")"
18-
<< " modelName=\"" << m.modelName << "\""
19-
<< " guid=\"" << guid() << "\""
20-
<< " generationTool=\"fmu4cpp"
21-
<< " v" << to_string(library_version()) << "\""
22-
<< " generationDateAndTime=\"" << now() << "\""
23-
<< " description=\"" << m.description << "\""
24-
<< " author=\"" << m.author << "\""
25-
<< " variableNamingConvention=\"" << m.variableNamingConvention << "\""
26-
<< ">\n";
27-
28-
ss << "\t" << std::boolalpha
29-
<< "<CoSimulation needsExecutionTool=\"" << m.needsExecutionTool << "\""
30-
<< " modelIdentifier=\"" << m.modelIdentifier << "\""
31-
<< " canHandleVariableCommunicationStepSize=\"" << m.canHandleVariableCommunicationStepSize << "\""
32-
<< " canBeInstantiatedOnlyOncePerProcess=\"" << m.canBeInstantiatedOnlyOncePerProcess << "\""
33-
<< " canGetAndSetFMUstate=\"" << m.canGetAndSetFMUstate << "\""
34-
<< " canSerializeFMUstate=\"" << m.canSerializeFMUstate << "\""
35-
<< R"( canNotUseMemoryManagementFunctions="true")"
15+
ss << R"(<?xml version="1.0" encoding="UTF-8"?>)" << "\n"
16+
<< "<fmiModelDescription\n"
17+
<< "\tfmiVersion=\"2.0\"\n"
18+
<< "\tmodelName=\"" << m.modelName << "\"\n"
19+
<< "\tguid=\"" << guid() << "\"\n"
20+
<< "\tgenerationTool=\"fmu4cpp v" << to_string(library_version()) << "\"\n"
21+
<< "\tgenerationDateAndTime=\"" << now() << "\"\n"
22+
<< "\tdescription=\"" << m.description << "\"\n"
23+
<< "\tauthor=\"" << m.author << "\"\n"
24+
<< "\tvariableNamingConvention=\"" << m.variableNamingConvention << "\""
25+
<< ">\n\n";
26+
27+
ss << std::boolalpha
28+
<< "\t<CoSimulation\n"
29+
<< "\t\tneedsExecutionTool=\"" << m.needsExecutionTool << "\"\n"
30+
<< "\t\tmodelIdentifier=\"" << m.modelIdentifier << "\"\n"
31+
<< "\t\tcanHandleVariableCommunicationStepSize=\"" << m.canHandleVariableCommunicationStepSize << "\"\n"
32+
<< "\t\tcanBeInstantiatedOnlyOncePerProcess=\"" << m.canBeInstantiatedOnlyOncePerProcess << "\"\n"
33+
<< "\t\tcanGetAndSetFMUstate=\"" << m.canGetAndSetFMUstate << "\"\n"
34+
<< "\t\tcanSerializeFMUstate=\"" << m.canSerializeFMUstate << "\"\n"
35+
<< "\t\tcanNotUseMemoryManagementFunctions=\"true\""
3636
<< ">\n"
37-
<< "\t</CoSimulation>"
38-
<< "\n";
37+
<< "\t</CoSimulation>\n\n";
3938

4039
if (!m.vendorAnnotations.empty()) {
4140
ss << "\t<VendorAnnotations>\n";
4241
for (const auto &annotation: m.vendorAnnotations) {
4342
std::string indentedAnnotation = indent_multiline_string(annotation, 3);
4443
ss << indentedAnnotation << "\n";
4544
}
46-
ss << "\t</VendorAnnotations>\n";
45+
ss << "\t</VendorAnnotations>\n\n";
46+
}
47+
48+
if (m.defaultExperiment) {
49+
ss << "\t<DefaultExperiment ";
50+
51+
ss << "startTime=\"" << m.defaultExperiment->startTime << "\"";
52+
if (m.defaultExperiment->stopTime) ss << " stopTime=\"" << *m.defaultExperiment->stopTime << "\"";
53+
if (m.defaultExperiment->stepSize) ss << " stepSize=\"" << *m.defaultExperiment->stepSize << "\"";
54+
if (m.defaultExperiment->tolerance) ss << " tolerance=\"" << *m.defaultExperiment->tolerance << "\"";
55+
56+
ss << "/>\n\n";
4757
}
4858

4959
ss << "\t<ModelVariables>\n";
@@ -111,7 +121,7 @@ std::string fmu_base::make_description() const {
111121
<< "\n";
112122
}
113123

114-
ss << "\t</ModelVariables>\n";
124+
ss << "\t</ModelVariables>\n\n";
115125

116126
ss << "\t<ModelStructure>\n";
117127

@@ -157,7 +167,7 @@ std::string fmu_base::make_description() const {
157167
ss << "\t\t</InitialUnknowns>\n";
158168
}
159169

160-
ss << "\t</ModelStructure>\n";
170+
ss << "\t</ModelStructure>\n\n";
161171

162172
ss << "</fmiModelDescription>\n";
163173

export/src/fmu4cpp/fmi3/fmi3_description.cpp

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,37 @@ namespace {
2424
throw std::runtime_error("Unknown variable type");
2525
}
2626

27-
}
27+
}// namespace
2828

2929

3030
std::string fmu_base::make_description() const {
3131

3232
const model_info m = get_model_info();
3333
std::stringstream ss;
34-
ss << R"(<?xml version="1.0" encoding="UTF-8"?>)"
35-
<< "\n"
36-
<< R"(<fmiModelDescription fmiVersion="3.0")"
37-
<< " modelName=\"" << m.modelName << "\""
38-
<< " instantiationToken=\"" << guid() << "\""
39-
<< " generationTool=\"fmu4cpp"
40-
<< " v" << to_string(library_version()) << "\""
41-
<< " generationDateAndTime=\"" << now() << "\""
42-
<< " description=\"" << m.description << "\""
43-
<< " author=\"" << m.author << "\""
44-
<< " variableNamingConvention=\"" << m.variableNamingConvention << "\""
45-
<< ">\n";
46-
47-
ss << "\t" << std::boolalpha
48-
<< "<CoSimulation needsExecutionTool=\"" << m.needsExecutionTool << "\""
49-
<< " modelIdentifier=\"" << m.modelIdentifier << "\""
50-
<< " canHandleVariableCommunicationStepSize=\"" << m.canHandleVariableCommunicationStepSize << "\""
51-
<< " canBeInstantiatedOnlyOncePerProcess=\"" << m.canBeInstantiatedOnlyOncePerProcess << "\""
52-
<< " canGetAndSetFMUstate=\"" << m.canGetAndSetFMUstate << "\""
53-
<< " canSerializeFMUstate=\"" << m.canSerializeFMUstate << "\""
54-
<< R"( canNotUseMemoryManagementFunctions="true")"
55-
<< ">\n"
56-
<< "\t</CoSimulation>"
57-
<< "\n";
34+
ss << R"(<?xml version="1.0" encoding="UTF-8"?>)" << "\n"
35+
<< "<fmiModelDescription fmiVersion=\"3.0\"\n"
36+
<< "\tmodelName=\"" << m.modelName << "\"\n"
37+
<< "\tinstantiationToken=\"" << guid() << "\"\n"
38+
<< "\tgenerationTool=\"fmu4cpp v" << to_string(library_version()) << "\"\n"
39+
<< "\tgenerationDateAndTime=\"" << now() << "\"\n"
40+
<< "\tdescription=\"" << m.description << "\"\n"
41+
<< "\tauthor=\"" << m.author << "\"\n"
42+
<< "\tvariableNamingConvention=\"" << m.variableNamingConvention << "\""
43+
<< ">\n\n";
44+
45+
ss << std::boolalpha
46+
<< "\t<CoSimulation\n"
47+
<< "\t\tneedsExecutionTool=\"" << m.needsExecutionTool << "\"\n"
48+
<< "\t\tmodelIdentifier=\"" << m.modelIdentifier << "\"\n"
49+
<< "\t\tcanHandleVariableCommunicationStepSize=\"" << m.canHandleVariableCommunicationStepSize << "\"\n"
50+
<< "\t\tcanBeInstantiatedOnlyOncePerProcess=\"" << m.canBeInstantiatedOnlyOncePerProcess << "\"\n"
51+
<< "\t\tcanGetAndSetFMUstate=\"" << m.canGetAndSetFMUstate << "\"\n"
52+
<< "\t\tcanSerializeFMUstate=\"" << m.canSerializeFMUstate << "\"\n"
53+
<< "\t\tprovidesDirectionalDerivatives=\"false\"" << "\n"
54+
<< "\t\tprovidesAdjointDerivatives=\"false\"" << "\n"
55+
<< "\t\tprovidesPerElementDependencies=\"false\"" << "\n"
56+
<< "\t\tprovidesEvaluateDiscreteStates=\"false\""
57+
<< "/>\n\n";
5858

5959
// if (!m.vendorAnnotations.empty()) {
6060
// ss << "\t<Annotations>\n";
@@ -65,6 +65,17 @@ std::string fmu_base::make_description() const {
6565
// ss << "\t</Annotations>\n";
6666
// }
6767

68+
if (m.defaultExperiment) {
69+
ss << "\t<DefaultExperiment ";
70+
71+
ss << "startTime=\"" << m.defaultExperiment->startTime << "\"";
72+
if (m.defaultExperiment->stopTime) ss << " stopTime=\"" << *m.defaultExperiment->stopTime << "\"";
73+
if (m.defaultExperiment->stepSize) ss << " stepSize=\"" << *m.defaultExperiment->stepSize << "\"";
74+
if (m.defaultExperiment->tolerance) ss << " tolerance=\"" << *m.defaultExperiment->tolerance << "\"";
75+
76+
ss << "/>\n\n";
77+
}
78+
6879
ss << "\t<ModelVariables>\n";
6980

7081
const auto allVars = [&] {
@@ -131,7 +142,7 @@ std::string fmu_base::make_description() const {
131142
// }
132143
}
133144

134-
ss << "\t</ModelVariables>\n";
145+
ss << "\t</ModelVariables>\n\n";
135146

136147
ss << "\t<ModelStructure>\n";
137148

@@ -173,7 +184,7 @@ std::string fmu_base::make_description() const {
173184
}
174185
}
175186

176-
ss << "\t</ModelStructure>\n";
187+
ss << "\t</ModelStructure>\n\n";
177188

178189
ss << "</fmiModelDescription>\n";
179190

src/model.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ model_info fmu4cpp::get_model_info() {
8383
info.modelName = "Identity";
8484
info.description = "A simple feed-trough model";
8585
info.modelIdentifier = FMU4CPP_MODEL_IDENTIFIER;
86+
info.defaultExperiment = {0.0, 10};
87+
8688
return info;
8789
}
8890

0 commit comments

Comments
 (0)