use of com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator in project osp-validator by open-simulation-platform.
the class ValidateModelDescriptionDataModel method main.
public static void main(String[] args) {
ModelDescription modelDescription = new ModelDescription();
Unit unit = new Unit();
unit.setExponent(Unit.Exponent.KILOGRAM, 1);
Variable v1 = new Variable();
v1.setCausality(Variable.Causality.OUTPUT);
v1.setType(Variable.Type.REAL);
v1.setName("v1");
v1.setUnit(unit);
Variable v2 = new Variable();
v2.setCausality(Variable.Causality.OUTPUT);
v2.setType(Variable.Type.REAL);
v2.setName("v2");
v2.setUnit(unit);
Variable v3 = new Variable();
v3.setCausality(Variable.Causality.INPUT);
v3.setType(Variable.Type.REAL);
v3.setName("v3");
v3.setUnit(unit);
Variable v4 = new Variable();
v4.setCausality(Variable.Causality.INPUT);
v4.setType(Variable.Type.REAL);
v4.setName("v4");
v4.setUnit(unit);
Force force = new Force();
force.setName("force");
force.setVariables(Arrays.asList(v1, v2));
LinearVelocity linearVelocity = new LinearVelocity();
linearVelocity.setName("linearVelocity");
linearVelocity.setVariables(Arrays.asList(v3, v4));
LinearMechanicalPort linearMechanicalPort = new LinearMechanicalPort();
linearMechanicalPort.setName("linearMechanicalPort");
linearMechanicalPort.setForce(force);
linearMechanicalPort.setLinearVelocity(linearVelocity);
modelDescription.getUnits().add(unit);
modelDescription.getVariables().addAll(Arrays.asList(v1, v2, v3, v4));
modelDescription.getForces().add(force);
modelDescription.getLinearVelocities().add(linearVelocity);
modelDescription.getLinearMechanicalPorts().add(linearMechanicalPort);
ModelDescriptionValidator validator = new ModelDescriptionValidator();
List<ValidationDiagnostic<Object>> diagnostics = validator.validate(modelDescription);
for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
System.out.println("Message: " + diagnostic.getErrorMessage());
System.out.println("Object: " + diagnostic.getValidatedObject());
}
}
use of com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator in project osp-validator by open-simulation-platform.
the class Validator method getModelDescriptionErrorMessages.
private List<String> getModelDescriptionErrorMessages(File ospSystemStructureFile, OspSystemStructure ospSystemStructureElement) {
List<String> errorMessages = new ArrayList<>();
for (Simulators.Simulator simulator : ospSystemStructureElement.getSimulators().getSimulator()) {
FmuLocator fmuLocator = new DefaultFmuLocator(ospSystemStructureFile);
URI fmu = fmuLocator.get(simulator);
OspModelDescriptionLocator ospModelDescriptionLocator = new DefaultOspModelDescriptionLocator(ospSystemStructureFile, fmuLocator);
Optional<File> ospModelDescriptionXml = ospModelDescriptionLocator.get(simulator);
if (ospModelDescriptionXml.isPresent()) {
OspModelDescriptionParser parser = new OspModelDescriptionParser();
OspModelDescriptionType ospModelDescriptionElement = parser.parse(ospModelDescriptionXml.get());
Map<Object, Location> locations = parser.getLocations();
ModelDescriptionFactory factory = new ModelDescriptionFactory();
ModelDescription modelDescription = factory.create(ospModelDescriptionXml.get(), fmu);
Simulator s = new Simulator();
s.setName(simulator.getName());
s.setModelDescription(modelDescription);
SystemStructure systemStructure = new SystemStructure();
systemStructure.getSimulators().add(s);
ModelDescriptionValidator validator = new ModelDescriptionValidator();
List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
Map<Object, Object> coreToJaxb = createModelDescriptionMap(ospModelDescriptionElement, modelDescription);
errorMessages.addAll(getErrorMessages(ospModelDescriptionXml.get(), locations, diagnostics, coreToJaxb));
}
}
return errorMessages;
}
use of com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator in project osp-validator by open-simulation-platform.
the class ValidateOspModelDescriptionFile method main.
public static void main(String[] args) throws URISyntaxException {
File ospModelDescriptionFile = new File("/path/to/OspModelDescription.xml");
URI fmu = new URI("file:///path/to/model.fmu");
ModelDescriptionFactory factory = new ModelDescriptionFactory();
ModelDescription modelDescription = factory.create(ospModelDescriptionFile, fmu);
ModelDescriptionValidator validator = new ModelDescriptionValidator();
List<ValidationDiagnostic<Object>> diagnostics = validator.validate(modelDescription);
for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
System.out.println("Message: " + diagnostic.getErrorMessage());
System.out.println("Object: " + diagnostic.getValidatedObject());
}
}
Aggregations