Tested with:
MSL Versions:
3.2.1, 2013-08-14, build 2 (2013-08-14 08:44:41Z)
3.2.1, 2013-08-14, build 4 (2015-09-30 09:15:00Z)
Below is a model with 4 components:
Mass flow source (M_bound)
AbruptAdapter (abruptAdapter)
Dynamic Pipe (pipeSmall)
Pressure Source (P_bound)
Two connection cases of the model are also contained in the equation section:
Case #1: M_bound -> abruptAdaptor -> pipeSmall -> P_bound
Case #2: M_bound -> pipeSmall -> abruptAdaptor -> P_bound
Summary: Case #1 simulates fine but Case #2 fails. The error generated is shown below:
The following error was detected at time: 0
Model error - division by zero: (data.zeta1) / ((if data.zeta1_at_a then rho_a_des*A_a^2 else rho_b_des*A_b^2)) = (0.402964) / (0)
The stack of functions is:
Modelica.Fluid.Fittings.BaseClasses.QuadraticTurbulent.pressureLoss_m_flow_totalPressure
Modelica.Fluid.Fittings.BaseClasses.QuadraticTurbulent.pressureLoss_m_flow_totalPressure(
-pipeBig.port_b.m_flow,
abruptAdaptor.state_a.d,
abruptAdaptor.state_b_des.d,
abruptAdaptor.state_b.d,
abruptAdaptor.state_a_nondes.d,
abruptAdaptor.data,
abruptAdaptor.m_flow_small)
First evaluation failed for non-linear solver.
Question: Why does Case #2 fail and recommendations on how to fix it? Any insight would be great. It may even be a bug in the AbruptAdaptor component.
Model Code
model AbruptAdaptor_1Pipe
replaceable package Medium = Modelica.Media.Water.StandardWater;
inner Modelica.Fluid.System system;
Modelica.Fluid.Sources.Boundary_pT P_bound(
redeclare package Medium = Medium,
nPorts=1,
p=system.p_ambient,
T=M_bound.T);
Modelica.Fluid.Sources.MassFlowSource_T M_bound(
redeclare package Medium = Medium,
m_flow=1,
T=300,
nPorts=1);
Modelica.Fluid.Fittings.AbruptAdaptor abruptAdaptor(
redeclare package Medium = Medium,
diameter_a=1,
diameter_b=0.5,
m_flow_nominal=M_bound.m_flow,
m_flow_start=M_bound.m_flow);
Modelica.Fluid.Pipes.DynamicPipe pipeSmall(
redeclare package Medium = Medium,
T_start=M_bound.T,
m_flow_start=M_bound.m_flow,
length=1,
diameter=0.5,
modelStructure=Modelica.Fluid.Types.ModelStructure.av_b); // switch to av_vb with case #2
equation
// Case #1
connect(M_bound.ports[1],abruptAdaptor.port_a);
connect(abruptAdaptor.port_b,pipeSmall.port_a);
connect(pipeSmall.port_b,P_bound.ports[1]);
// Case #2
//connect(M_bound.ports[1],pipeSmall.port_b);
//connect(abruptAdaptor.port_b,pipeSmall.port_a);
//connect(abruptAdaptor.port_a,P_bound.ports[1]);
annotation (uses(Modelica(version="3.2.1")));
end AbruptAdaptor_1Pipe;
your staggered grid is fine, you set volumes where you had to.
Don't worry, it's not your fault, is a debug, I tried to use it several times, and it always fails in one of the ways (I don't know the position of your adaptor, but it doesn't really matter). You can always use orifices where you define the relations dp(Areas_rate), avoiding reversal flows in both cases, so connecting two volumes before and after the orifices (like two valves in parallel).
That should work.
Related
I have a full stable diffusion image to image model working on Colab, powered by Gradio. However, it requries nvidia gpu. When I deploy it to hugging face spaces, a runtime error occurs:
RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx
How do i deploy the model? Is there some other way to deploy the model, like some resources for deploying on AWS, Azure, for free.
Here's the main code of the model:
def predict(img, strength, seed, prompt):
seed = int(seed)
img1 = np.asarray(img)
img2 = Image.fromarray(img1)
init_image = img2.resize((768, 512))
generator = torch.Generator(device=device).manual_seed(seed)
with autocast("cuda"):
image = pipe(prompt=prompt, init_image=init_image, strength=strength, guidance_scale=5, generator=generator).images[0]
return image
gr.Interface(
predict,
title = 'Image to Image using Diffusers',
inputs=[
gr.Image(),
gr.Slider(0, 1, value=0.05, label ="strength (keep it close to 0 to make minimal changes to image (such as 0.1, 0.2, 0.3)"),
gr.Number(label = "seed (any number, generally 1024. But it's totally random. Change it and see different outputs)"),
gr.Textbox(label="Prompt, empty by default")
],
outputs = [
gr.Image()
]
).launch()
Problem and Motivation:
the models of the fluid library in openmodelica are very elaborated, with a lot of parameters one has to set correctly to get the model running with acceptable results.
I want to set up an environment for daily engineering calculations, for mechanical and process engineers - no simulation experts.
So the components of my library must be pre-configured and the users shouldn't be forced to edit the code behind the graphical model (eg redeclaration of the Medium).
Idea:
drop the fluid models in own models, configure them properly, redeclare the Medium and provide fluid connectors.
model flowEncapsulateFluid1
inner Modelica.Fluid.System system;
replaceable package Medium = Modelica.Media.Water.ConstantPropertyLiquidWater constrainedby
Modelica.Media.Interfaces.PartialMedium "Medium in the component"
annotation (choicesAllMatching = true);
model myStaticPipe
Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium = Medium, allowFlowReversal = true, height_ab = 2, length = 2, diameter = 0.1);
Modelica.Fluid.Interfaces.FluidPort_a port_a;
Modelica.Fluid.Interfaces.FluidPort_b port_b;
equation
connect(pipe.port_b, port_b);
connect(port_a, pipe.port_a);
model myTank1
Modelica.Fluid.Vessels.OpenTank tank1(crossArea = 1,
redeclare package Medium = Medium, use_portsData = true, height = 12,
level_start = 8, nPorts = 6,
portsData = {Modelica.Fluid.Vessels.BaseClasses.VesselPortsData
(diameter = 0.1)});
Modelica.Fluid.Interfaces.FluidPort_a port_a
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a1
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a2
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a3
(redeclare package Medium = Medium) ;
Modelica.Fluid.Interfaces.FluidPort_a port_a4
(redeclare package Medium = Medium) ;
Modelica.Fluid.Interfaces.FluidPort_b port_b
(redeclare package Medium = Medium);
equation
connect(tank1.ports[6], port_b);
connect(port_a4, tank1.ports[5]);
connect(port_a3, tank1.ports[4]);
connect(port_a2, tank1.ports[3]);
connect(port_a1, tank1.ports[2]);
connect(port_a, tank1.ports[1]);
end myTank1;
package UnitTests
model Test1
flowEncapsulateFluid1.myTank1 myTank11;
myStaticPipe myStaticPipe1;
myTank1 myTank12;
equation
connect(myStaticPipe1.port_b, myTank12.ports_b);
connect(myTank11.ports_b, myStaticPipe1.port_a);
end Test1;
end UnitTests;
annotation(
uses(Modelica(version = "3.2.2")));
end flowEncapsulateFluid1;
I get the message "No corresponding 'inner' declaration found for component .Modelica.Fluid.System tank1.system declared as 'outer '.
The existing 'inner' components are:
There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: Modelica.Fluid.Vessels.OpenTank$tank1.
Check if you have not misspelled the 'outer' component name.
Please declare an 'inner' component with the same name in the top scope.
Continuing flattening by only considering the 'outer' component declaration."
I don't know how to interpret the message. Any help would be welcome.
Furthermore I would appreciate, if some one could provide me advices or links for this project.
Many thanks in advance.
y4cine,
You could create a library of components that extend from the Modelica.Fluid components and finalize the parameters that you don't want your users to see. For example
model myPipe
extends Modelica.Fluid.Pipes.DynamicPipe(
redeclare package Medium = Modelica.Media.Water.StandardWater,
final height_ab=0,
final isCircular=true);
end myPipe;
When you instantiate the component (shown in Dymola) the parameters are not visible (see screenshot below).
Best regards,
Rene Just Nielsen
In regards to this portion of your question: "No corresponding 'inner' declaration found for component .Modelica.Fluid.System tank1.system declared as 'outer '.
outer and inner are special key words in modelica.
The fluid library defines an "outer" model called "system" located at Modelica.Fluid.System. If you drag that into a model that gives that warning the issue will go away as it will find this outer model. Typically this system model should be at a high level and not at individual components...
Do you know how to plot a Gantt chart in Matlab without using a third-party software?
At the end I would love to obtain something like this:
What I was able to obtain so far is
using this code:
% Create data for childhood disease cases
measles = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884]';
mumps = [20178 23536 34561 37395 36072 32237 18597 9408 6005 6268 8963 13882]';
chickenPox = [37140 32169 37533 39103 33244 23269 16737 5411 3435 6052 12825 23332]';
% Create a stacked bar chart using the bar function
fig = figure;
bar(1:12, [measles mumps chickenPox], 0.5, 'stack');
axis([0 13 0 100000]);
title('Childhood diseases by month');
xlabel('Month');
ylabel('Cases (in thousands)');
legend('Measles', 'Mumps', 'Chicken pox');
That is not what I want but, maybe, goes in this direction
Here, I share the solution I have just found (maybe it is not the most elegant one but it works for the purpose I have):
[the main idea is to draw a bar and "delete" the beginning overdrawing up on it another white bar]
Let's say you have two vector:
start =[6907402; 2282194; 4579536; 2300332; 10540; 2307970; 4603492; 0];
stop =[9178344; 9168694;6895050; 4571400; 2280886; 4579044; 6897152 ;2271186];
There are 8 elements in each: every element is a task. In the start array, there is the start time of each task and in stop there is the end of the "execution" of a given task.
barh(stop)
hold on
barh(start,'w')
At the end here you have the Gantt:
UPDATE:
My scripts are evolved of course and, more, on the matlab website, there is more information. Here 2 example more to complete the answer:
Option 1:
Positions=[1,2,3,4];
Gap_Duration=[0,2,5,3,5,3;
3,5,3,5,3,4;
9,3,0,0,12,2;
13,2,2,2,8,3];
barh(Positions,Gap_Duration,'stacked');
Option 2:
Positions=[1,2,3,4];
Gap_Duration=[0,2,5,3,5,3;
3,5,3,5,3,4;
9,3,0,0,12,2;
13,2,2,2,8,3];
barh(Positions,Gap_Duration,'stacked');
set(H([1 3 5]),'Visible','off')
I'm trying to implement mouse selection for my game. When I QueryAABB it looks like it's treating objects much larger than they really are.
Here's what's going on in the image
The blue box is an actor containing a body that I'd like to select
The outline on the blue box is drawn by Box2DDebugRenderer
The mouse selects a region on the screen (white box), this is entirely graphical
The AABB is converted to meters and passed to QueryAABB
The callback was called for the blue box and turned it red
The green outline left behind is a separate body to check if my conversions were correct, this is not used for the actual selection process
It seems to be connected to my meter size, the larger it is, the more inaccurate the result is. At 1 meter = 1 pixel it works perfectly.
Meter conversions
val MetersToPixels = 160f
val PixelsToMeters = 1/MetersToPixels
def toMeters(n: Float) = n * PixelsToMeters
def toPixels(n: Float) = n * MetersToPixels
In the image I'm using MetersToPixels = 160f so the inaccuracy is more visible, but I really want MetersToPixels = 16f.
Relevant selection code
val x1 = selectPos.x
val y1 = selectPos.y
val x2 = getX
val y2 = getY + getHeight
val (l,r) =
if (x2 < x1)
(x2,x1)
else
(x1,x2)
val (b,t) =
if (y2 < y1)
(y2,y1)
else
(y1,y2)
world.QueryAABB(selectCallback, toMeters(l),toMeters(b), toMeters(r),toMeters(t))
This code is inside the act method of my CursorActor class. And selectPos represents the initial point where the use pressed down the left mouse button and getX and getY are Actor methods giving the current position. The next bit sorts them because they might be out of order. Then they are converted to meters because they are all in pixel units.
selectCallback: QueryCallback
override def reportFixture(fixture: Fixture): Boolean = {
fixture.getBody.getUserData match {
case selectable: Selectable =>
selected += selectable
true
case _ => true
}
}
Selectable is a trait that sets a boolean flag internally after the query which helps determines the color of the blue box. And selected is a mutable.HashSet[Selectable] defined inside of CursorActor.
Other things possibly worth noting
I'm new to libgdx and box2d.
The camera is scaled x2
My Box2DDebugRenderer uses the camera's combined matrix multiplied by MetersToPixels
From what I was able to gather, QueryAABB is naturally inaccurate for optimization. However, I've hit a roadblock with libgdx because it doesn't have any publicly visible function like b2testOverlap and from what I understand, there's no plan for there to be one any time soon.
I think my best solution would probably be to use jbox2d and pretend that libgdx's physics implementation doesn't exist.
Or as noone suggested I could add it to libgdx myself.
UPDATE
I decided to go with a simple solution of gathering the vertices from the fixture's shape and using com.badlogic.gdx.math.Intersector against the vertices of the selection. It works I guess. I may stop using QueryAABB all together if I decide to switch to using a sensor for the select box.
I can't seem to figure out how to calculate an azimuth of a star, let's say Sirius, when it is at alt=0 (star rise/star set).
So essentially in the end I will have two values.
Sirius.az # star rise
Sirius.az # star set
Is this possible?
THANKS!
Simply check the .az attribute of the star once your observer object has determined the moment of rising or setting. For example:
import ephem
s = ephem.star('Sirius')
boston = ephem.Observer()
boston.lat = '42.37'
boston.lon = '-71.03'
boston.next_rising(s)
print s.alt, s.az
boston.next_setting(s)
print s.alt, s.az
Running this script at this moment gives me the encouraging output:
0:00:00.0 112:23:25.2
0:00:00.0 247:36:34.9
As you can see, the rising and setting routines have already established the moment of zero altitude, leaving the azimuth for you to read off and use!