Haml-scais is a project mainly written in Ruby, based on the MIT license.
= haml-scais
haml-scais attempts to simplify scais xml generation by extending haml features to add scais module generation.
== Features
== Getting Started
First you should download the latest haml and haml-scais version.
You can include haml-scais instruction in your haml file just like any code but at generation time you should execute haml-scais command instead of haml.
== Example
Create a topology file 'topo.haml' and copy the following lines.
!!!XML = topo = Topology.new('TankVolumeAuto').description('Tank Topology for Volume Automatic Protection').name('TopoTankVolumeAuto') do |topo|
Now lets generate the xml haml-scais topo.haml topo.xml
The resulting xml should be something like this
<?xml version='1.0' encoding='utf-8' ?>
== Topology
To create a topology use Topology class. As with all haml-scais classes you can set Topology attributes on creation time or set the later. When creating the topology you have to at least specify a code that uniquelly identifies this object. Usually attributes setter apart from usual syntax (setter= value) accepts another one (setter(value)). The second one is chainable, meaning that afterwards you can callother method from this object including setter:
Topology.new('Topo').name('This is my name').description('And my description')
Topology.new('Topo', :name => 'This is my name', :description => 'And my description')
You can set the following properties of a topology:
The topology class automatically sets the other properties based on your scais install.
Also the topology will add an automatic index to every block added to it. Topology.new('Topo') do |topo| topo.add_block Fint.new('BF-1') # this block has index 1 topo.add_block Fint.new('BF-2').index(3) # this block has index 3 topo.add_block Fint.new('BF-3') # this block has index 4 end
To add blocks to a topology we use add_block method. This can be called either with a topology block or a ruby block evaluating to a topology block. These three chunks of code are equivalent topo.add_block Fint.new('BF-2').index(3)
topo.add_block do Fint.new('BF-2').index(3) end
topo.add_block do fint = Fint.new('BF-2') fint.index(3) # remember that most setter methods in this form return the block end
You can print the topology xml structure using to_xml method
== Topology Blocks
All blocks are subclasses of Block::Base so they all have a similar behaviour.
Common block attributes
Setting outputs block.outputs do output # output with default configuration output.save(true).alias('Output 0') # output saved, with alias 'Output 0' ... end
Setting inputs
fu = Funin.new('B1') ... vm = Vmetodo.new('BVm') ...
block = ... # block of some kind
block.inputs do input.from('B1.O0') # input as block.output input.from('B1') # if no output given, default is O0 input.from(fu) # if block given, takes O0 from block input.from(fu.output(0)) # also you can give the output directly end
block.inputs do input.from('BVm.YP1') input.from(vm.output(:yp1)) end
=== Funin To set up funin formula, use the formula chainable method funin.formula formula_string
Example funin = Funin.new('B8', :name =>'FUNIN EXP-2', :active => true).debug(:fatal).index(8).modes('B') funin.outputs do output.save(true).alias('ANALYT2') end funin.inputs do input.alias('I0').from('B1').modes('B') end funin.formula "I0+sqrt(2/5)exp((TAU-TIME)/2)sin(0.5(sqrt(5)(TIME-TAU)*PI)"
=== Fint To create a fint module you have to set times and coefs. This are chainable methods that accept arrays of values
Example fint = Fint.new('B1').name('FINT TRIGGER').debug(:info).index(1).modes('ALL') fint.outputs do output.save(true).alias('TRIGGER') end fint.times([-100,0.1,0.1,100]) fint.coefs([0,0,1,1])
=== Convex
Example c = Convex.new('B9', :name => 'CONVEX LAG-2MODE').active(true).debug(:info).index(9).modes('B') c.outputs do output.save(true).alias('NUM-B') end c.inputs do input.from('B7').modes('B') end c.roots = [-0.5, 0.5] c.vforz = 0
=== Logate
Example logate = Logate.new('B16').name('MULTIPLEXOR').active(true).debug(:info).index(16).modes('ALL') logate.outputs do output.alias('MULTIPLEXACION').save(true) end logate.inputs do input.alias('I0').from('B1').modes('ALL') end logate.high.from('B14').modes('ALL').alias('IN_HIGH') logate.low.from('B15').modes('ALL').alias('IN_LOW') logate.condition "I0>0" logate.initial_output(0, :alias => 'INITSTATE')
=== LogateHandler
Example lh = LogateHandler.new('B5').name('LogateModeChange').debug(:info).active(true).index(5).modes('ALL') lh.outputs do output.alias('LOGAT1') end lh.inputs do input.from('B4').alias('I0').modes('ALL') end lh.previous_output :alias => 'PREVOUT' lh.initial_output(0, :alias => 'INITOUT') lh.precision 0.005 lh.condition "(TIME<2.3) and (I0>1)"
=== Vmetodo
Example topo = Topology.new("OsciladorVanPol", :description => "Diferential Ecuation Resolution", :name => "OsciladorVanPol") do |topo| b1 = Vmetodo.new('B1').name('VMETODO').active(true).debug(:info).modes('ALL') b1.yp1 'y2', :alias => 'yp1', :save => true b1.yp2 '-y1 + cos(1.41 * Vmetodo::TIME)', :alias => 'yp2', :save => true b1.y1 0.01, :alias => :y1, :save => true b1.y2 0.00001, :alias => :y2, :save => true topo.add_block b1 end
=== Files
Example b = Files.new('B1').name('FILES Triple BC').active(true).debug(:info).index(1).modes('ALL') b.outputs do output.save(true).alias('BC-1') output.save(true).alias('BC-2') output.save(true).alias('BC-3') end b.file 'path-to-file/data.dat' b.select_for 'O0', :time => 0, :value => 1 b.select_for 'O1', :time => 0, :value => 2 b.select_for 'O2', :time => 3, :value => 4
=== Acelerator Example Acelerator.new('Acc1', :mode => 'PASSIVE').threshold(1).max_iterations(10)
== Contributing to haml-scais
== Copyright
Copyright (c) 2011 nico. See LICENSE.txt for further details.