Openmodelica How to take input for model and use OMshell - openmodelica

I am new to openModelica
this is "working" but I want to take input in this model file using OMshell
How to take input instead of = 10;
I have not used function as der() is not allowed in function
model Fluid
parameter Real Fci(unit = "kg/h")=10 "Feed cold in/out";
parameter Real Fhi(unit = "kg/h")=10 "Feed hot in/out";
parameter Real Tci(unit = "K")=10 "Temp cold in";
parameter Real Thi(unit = "K")=0 "Temp hot in";
parameter Real Tho(unit = "K")=-1 "Temp hot out";
parameter Real U(unit = "kg/Km^2s^2")=10 "Heat transfer coefficient";
parameter Real Area(unit = "m^2")=10 "Area";
parameter Real Volume(unit = "m^3")=10 "Volume";
parameter Real Density(unit = "kg/m^3")=10 "Density";
parameter Real Cp(unit = "Jkg^-1K-1")=10 "Specific Heat";
Real Tco;
equation
der(Tco)=(Fci*Cp*Density*(Tci-Tco)-U*Area*((Tci-Thi)-(Tco-Tho))/log((Tci-Thi)/(Tco-Tho)))/(Volume*Cp*Density);
end Fluid;
I want something like this
I want this in OMshell
>loadFile("Fluid.mo")
>Fluid(1,2,3,4,5,6,7,8,9,10)
>simulate(Fluid,startTime=0,stopTime=5)
>plot(Tco)

You wanted this:
loadFile("Fluid.mo")
Fluid(1,2,3,4,5,6,7,8,9,10)
simulate(Fluid,startTime=0,stopTime=5)
plot(Tco)
But you should be able to use:
loadFile("Fluid.mo")
simulate(Fluid,startTime=0,stopTime=5,simflags="-override Fci=1,Fhi=2")
plot(Tco)

Related

M (PowerQuery), set the value of a non-primitive variable in a let statement

I'm writing a custom M Language (PowerQuery in Excel) function to query a RESTful interface. This interface has a large number of optional parameters.
Starting with a simple case- I handle an optional limit passed as a simple (primitive) value as follows-
/*
* RESTful API Get from the named endpoint
*/
(endpoint as text, optional limit) =>
let
// query limit
// If limit is supplied as a number, it will be converted to text
// If limit is not supplied it will be set to the value "1000"
limit = if limit <> null then Text.From(limit) else "1000",
As the full API has many paramaters I wanted to use a Record to pass them to the function, but then I realised I don't know how to persuade M to write the default values into the parameter record.
I tried a couple of options.
Direct access-
(endpoint as text, optional params as record) =>
let
params[limit] = if (params[limit] = null) then "1000",
the result is a syntax error-'Token equal expected'
Merging the new value of limit as a Record with "&"
(endpoint as text, optional params as record) =>
let
params = params & if params[limit] = null then [limit = "1000"] else [],
result syntax error-'Token Literal expected'
I'm clearly missing something about the syntax rules for let statements, I know I need a variable = value assignment, and it looks as if putting anything other than a plain variable name on the LHS to write elements inside a structured value is not allowed, but i'm not sure how to acieve this otherwise?
Not sure exactly what you want here, but to create a List of Records where some Records have a default parameter and others do not, you could try something like:
(newParams as record) =>
let
default = [limit=1000, param2=2, param3=3],
final = Record.Combine({default, newParams})
in
final
With regard to Record.Combine, the beauty is that the right hand record will override the left hand record if both are present; and it will just add to it if nothing is present.
So something like:
let
Source = [limit=400, param3="x", param7=246],
conv = fnParams(Source)
in
conv
=>
Depending on the required format of your output string, you can build it using List.Accumulate. eg:
let
Source = [limit=400, param3="x", param7=246],
conv = fnParams(Source),
list = List.Accumulate(List.Zip({Record.FieldNames(conv), Record.ToList(conv)}), "",
(state,current) =>state & "&" & current{0} & "=" & Text.From(current{1}) )
in
list
=> &limit=400&param2=2&param3=x&param7=246

Filter leading to different results when typed manually and via defined as a variable

I'm trying to create a calculated column indicating if a team has a prize or not from the table below:
To do that I need to count within the group if there's a player whose "Prize" field is not empty. Here's the 1st attempt:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,len(Table4[Prize])>0)),Player_Same_Team)>0
Looks like it's going what I intend it to do. However, when I swap the filter content to a pre-defined variable, it gave me results that don't make sense:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,Has_Prize)),Player_Same_Team)>0
The typed content len(Table4[Prize])>0 is the same as that in the variable, so what may be causing the difference? Thanks for your help.
As soon as you assign it to a variable, the value of the variable remains constant. Therefore the Len is evaluated to a value, that you are then passing as a filter.
The first example works because the CALCULATE accepts a table as a parameter, and player_same_team is evaluated to a table, by using the FILTER expression.
In order for what you are trying to do to work it would have to be something like this:
= Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = filter(Table4,len(Table4[Prize])>0)
Return calculate(countrows(Has_Prize),Player_Same_Team)>0
You can also write the measure in a slightly different way:
= CALCULATE ( COUNT(Table4[Team]),
ALLEXCEPT(Table4[Team]),
LEN(Table4[Prize])>0) > 0

Checking Ontology Consistency in Run Time

I have a program that uses Jena to load an .owl Ontology designed in Protege. I am trying to do reasoning over it using Pellet in a way that if I add some statements in run time to model be able to check its consistency. For example I have 'Method', 'Signature' and 'hasSignature' concepts in which hasSignature is an object property. I have following axiom:
Method hasSignature exactly 1 Signature
When I add some instance statements in order to violate above axiom no inconsistency is reported. Here is my code:
List<Statement> statements = new ArrayList<>();
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF);
FileManager.get().readModel(model, "Ontologies\\Ontology.owl");
OntClass Method = model.createClass( ns + "Method");
Individual method1 = Method.createIndividual(ns + "method1");
OntClass Signature = model.createClass( ns + "Signature");
Individual sign1 = Signature.createIndividual(ns + "sign1");
Individual sign2 = Signature.createIndividual(ns + "sign2");
Property hasSignature = model.createObjectProperty(ns + "hasSignature");
Statement st = model.createStatement(method1, hasSignature, sign1);
statements.add(st);
Statement st1 = model.createStatement(method1, hasSignature, sign2);
statements.add(st1);
Reasoner reasoner = PelletReasonerFactory.theInstance().create();
InfModel inf = ModelFactory.createInfModel(reasoner, model.add(statements));
System.out.println(inf.validate().isValid());
What's wrong? Why it doesn't work?
You have not declared sign1 and sign2 to be different from each other. So, since it is possible for the two individuals to be sameAs each other, the reasoner has determined that that's the only case not rising a clash. Therefore the ontology is consistent.

How can I use Distinct on a group of bags in pig

This is my input as described below:
({(Fish M.),(Fish M.),(Fish M.),(Fish M.),(Fish M.)},{(Acasuso J.),(Acasuso J.),(Acasuso J.),(Acasuso J.),(Acasuso J.)},{(8/23/2007),(8/23/2007),(8/23/2007),(8/23/2007),(8/23/2007)},{(99.84002222685783),(58.173357215875676),(PSL),(41.66666501098216),(EXW)})
I would like to do a distinct on the first and second bags to get one result each to produce an output like this:
(Fish M., Acasuso J., 8/23/2007, 99.84002222685783, 58.173357215875676, PSL, 41.66666501098216, EXW)
This script should work, I have ignored the last bag in your entry for brevity.
rr = load 'data/pig/input/Pig_DataSets/six' using CustomLoadFunction() as (one:bag{tup1:(c1:chararray)},two:bag{tup2:(c2:chararray)},three:bag{tup3:(c3:chararray)});
tt = foreach rr {
mm = two;
nn = distinct mm;
oo = one;
pp = distinct oo;
generate three,pp,nn;
};
You might have to use a custom load function because the the default loader wont work (unless you do some data cleansing). This post talks about a custom loader that might fit your scenario.

How to change start-index and max-results parameters by Java

As usual, I want to get more than 25 comment of a video by using Youtube API v2. Documents say that with start-index parameter, I can decide the interval and with maxresults parameter I can decide the max result. maxresults parameter is default 25 and is maximum 50. Iteratively i can get comments up to 1000. But, How can i change the maxresults parameter and star-index parameter in this code :
YouTubeService service = new YouTubeService(key);
String videoEntryUrl = "http://gdata.youtube.com/feeds/api/videos/0nvfsNzV3Vc";
VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class);
String commentUrl = videoEntry.getComments().getFeedLink().getHref();
CommentFeed commentFeed = service.getFeed(new URL(commentUrl),
CommentFeed.class);
for (CommentEntry comment : commentFeed.getEntries()) {
System.out.println(comment.getPlainTextContent());
}
Off memory, I think it is ( well should be )
String videoEntryUrl = "http://gdata.youtube.com/feeds/api/videos/0nvfsNzV3Vc?v=2&start-index=1&max-results=25";
Just set your start index to where you want to start from and then set how many results up to 50.

Resources