How do you apply src_indices in promotes_inputs=[], when you have multiple promoted inputs? - openmdao

The docs only show examples for when a component promotes a single input. How do I use src_indices to indicate that only one of my promoted inputs takes a certain slice?
p.model.add_subsystem('ComputeWakePosition', ComputeWakePosition(num_wake_points_per_side=4),
promotes_inputs=['wake_upper_lengths',
'wake_lower_lengths',
'wake_upper_angles',
'wake_lower_angles',
'displaced_cw_coordinates'], <-- I want to specify src_indices for this input only.
promotes_outputs=['upper_wake_coordinates',
'lower_wake_coordinates'])
I think I would be able to just use connect for that input, but given that everything else I've written doesn't use it, it'd be nice if there was a way to avoid it.

There is a function called promotes that you can call on your group after you've added a subsystem. In your code above, you could remove the promotion of the displaced_cw_coordinates variable from your add_subsystem call and make a separate call something like this p.model.promotes('ComputeWakePosition', inputs=['displaced_cw_coordinates'], src_indices=[2,4,6,8])

Related

Is there a way to pass arguments in a custom Excel 4.0 function?

First of all, don't bother answering "just use a newer version of Excel", I must use 4.0 for what I want to do, thanks.
.
Now, the question is simple (even if the answer may not be):
You can pass arguments in proper Excel functions (ex: =OPEN("foo.xls";3), opening foo.xls and updating all references without a prompt).
You can make custom functions (well, you can name ranges to call with parenthesis, ex: =CUSTOM_FUNCTION() and it will call that function until it hits return).
You can return values to the original function to use with =RETURN(foo).
.
Is it possible to have a custom function with custom arguments that you can call without storing them in cells, ex: you call =ADD_TWO_NUMBERS(1;2) calling ADD_TWO_NUMBERS(X;Y) (or whatever it needs to be for it to work) then =RETURN(x+y) returns 3 (obviously a stupid example, but just to explain my case).
I've tried to search for it, but I haven't found anything so far.

When to use '<event>'(event, instance) and when to use '<event>':function (event)?

I'm new to meteor, and I've followed different tutorials that explain and use things differently.
There seems to be two ways of processing an event. For example, if I want to manage a click on a tag, both of the following methods work :
This one is present on the hello world meteor app
'click p'(event, instance) {
}
This one is the one used in the tutorial.
'click p': function(event){
}
Both work perfectly and if I use both the last one will be effective. The weird thing is the color is not the same (on sublime text), the second has usual js colors but the first one is only green, orange, and everything else is white (on monokai).
I'm tempted to use the second one for better visibility, but I know I should not make that choice base on that. Which one is correct, and when ?
Bottom line: it doesn't really matter if you only need the event.
There are 2 syntactic differences between the functions, but there is no substantial difference:
The notation that you are using:
funcName(arg1, arg2)
vs
funcName: function(arg1, arg2)
The highlighting coloration difference you see in your editor is probably related to the shorthand notation. This shorthand notation is a feature of ES2015, the relatively new version of JS, and both are functionally identical. It is just syntactic sugar.
The arity (number of arguments).
The function is used as an event handler as a callback. Due to the dynamic nature of JavaScript, any function can be called with any number of parameters. The parameters are being assigned to arguments based on the function's definition, and are also dynamically available to the called function via the arguments pseudo-array.
The callback will always be called with 2 parameters. In the version with 1 argument, the second parameter will not be bound to any identifier within the function. You can omit the second argument if you don't need the template instance.

Can connectSlotsByName connect to selection model changes?

In my main window (QMainWindow) I have a QTableView (named commandsTableView). Now I want to react on its selection changes.
I made a slot and connected it manually to ui.commandsTableView->selectionModel(). All works fine.
But then I thought: why not use auto-connection (especially that there will be more connections to be done)? At least it will add more force to consistent naming rules.
Yet I wasn't able to find proper name syntax. I tried:
on_commandsTableView_selectionModel_selectionChanged,
on_commandsTableViewSelectionModel_selectionChanged,
on_commandsTableView_selectionChanged,
on_commandsTableView___selectionChanged
but neither worked. In all cases there is there is a message on output when running the app (with corresponding slot name, here only first given as an example):
QMetaObject::connectSlotsByName: No matching signal for on_commandsTableView_selectionModel_selectionChanged(QItemSelection,QItemSelection)
(Why there are no assertions in response for connection errors - that I cannot understand. I lost much time wondering what is wrong before I spotted those - and alike - messages on output.)
The object returned by ui.commandsTableView->selectionModel() has an empty name. But setting it to selectionModel prior to making a call to connectSlotsByName doesn't help either.
According to the documentation connectSlotsByName() only supports signatures like
void on_<object name>_<signal name>(<signal parameters>);
According to the sources that's the only form it checks (watch how it collects a list of children, then matches parent's method names against names of the children).
Hence, to be able to use auto-connection you would have needed a named selection model, which would continue existing from the call to connectSlotsByName() onwards. Each time you change the selection model (not likely) or the model (likely) you'd have to name the selection model and auto-connect again. But alas connectSlotsByName() will duplicate all other connections as it doesn't seem to check if connections are unique, so we have to connect signals to such dynamic children as models, scenes etc manually.
I think it's
on_selectionModel_selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)

How can I tell the Closure Compiler not to rename an inner function using SIMPLE_OPTIMIZATIONS?

How can I tell the Closure Compiler not to rename an inner function? E.g., given this code:
function aMeaninglessName() {
function someMeaningfulName() {
}
return someMeaningfulName;
}
...I'm fine with Closure renaming the outer function (I actively want it to, to save space), but I want the function name someMeaningfulName left alone (so that the name shown in call stacks for it is "someMeaningfulName", not "a" or whatever). This despite the fact that the code calling it will be doing so via the reference returned by the factory function, not by the name in the code. E.g., this is purely for debugging support.
Note that I want the function to have that actual name, not be anonymous and assigned to some property using that name, so for instance this is not a duplicate of this other question.
This somewhat obscure use case doesn't seem to be covered by either the externs or exports functionality. (I was kind of hoping there'd be some annotation I could throw at it.) But I'm no Closure Compiler guru, I'm hoping some of you are. Naturally, if there's just no way to do that, that's an acceptable answer.
(The use case is a library that creates functions in response to calls into it. I want to provide a version of the library that's been pre-compressed by Closure with SIMPLE_OPTIMIZATIONS, but if someone is using that copy of the library with their own uncompressed code and single-stepping into the function in a debugger [or other similar operations], I want them to see the meaningful name. I could get around it with eval, or manually edit the compressed result [in fact, the context is sufficiently unique I could throw a sed script at it], but that's awkward and frankly takes us into "not worth bothering" territory, hence looking for a simple, low-maintenance way.)
There is no simple way to do this. You would have to create a custom subclass of the CodingConvention class to indicate that your methods are "local" externs (support for this was added to handle the Prototype library). It is possible that InlineVariables, InlineFunctions, or RemoveUsedVariables will still try to remove the name and would also need to be fixed up.
Another approach is to use the source maps to remap the stack traces to the original source.
read the following section
https://developers.google.com/closure/compiler/docs/api-tutorial3#export
Two options basically, use object['functionName'] = obj.functionName or the better way
use exportSymbol and exportProperty both on the goog object, here is the docs link for that
http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.html
-- edit
ah, i see now, my first answer is not so great for you. The compiler has some interesting flags, the one which might interest you is DEBUG, which you can pass variables into the compiler which will allow you to drop some debugging annotations in via logging or just a string which does nothing since you are using simple mode.
so if you are using closure you can debug against a development version which is just a page built with dependiencies resolved. we also the drop the following in our code
if(DEBUG){
logger.info('pack.age.info.prototype.func');
}

How to programatically control an object's add-menu list of allowed content types?

I would like pragmatically to control individual objects' add-menu list of allowed content types.
I am building a collection of content types with archgenxml. In one case, I have a simulation class composed of a RangeBase class which has three realizations, valueRange, vectorRange and uniformRange. A simulation can contain exactly one range, i.e., RangeBase's multiplicity is one, so a simulation's add-menu should offer either all three range types or none at all.
To achieve this, I thought to subscribed to the IObjectInitializedEvent and IObjectRemovedEvent events; placing their respective handlers, initializedHook and removedHook, in the RangeBase class. The handlers would solicit an object's list of locally allowed types and remove or add the three ranges accordingly. After perusing the Plone's 'Community Developer Documentation', I thought the initializedHook code might look something like this:
# Set allowed content types
from Products.ATContentTypes.lib import constraintypes
def initializedHook(obj, event):
# Get this range's parent simulation
parent = obj.aq_parent
# Enable constraining
parent.setConstrainTypesMode(constraintypes.ENABLED)
# Remove the three ranges
allowedTypes = parent.getLocallyAllowedTypes()
ranges = ('valueRange','vectorRange','uniformRange')
for range in ranges:
allowedTypes.remove(range)
# Tweak the menu
parent.setLocallyAllowedTypes(allowedTypes)
parent.setImmediatelyAddableTypes(allowedTypes)
Unfortunately, my simulation class has none of these functions.
Is there an adaptor that will provide my simulation class with this functionality, or are there other altogether different approaches to achieve the desired menu behaviour? Any suggestions would be appreciated.
It is possible.
I believe you need to override getLocallyAllowedType()
http://svn.plone.org/svn/collective/Products.ATContentTypes/trunk/Products/ATContentTypes/lib/constraintypes.py
AT was written time before adapters, so AT is not using it.
I suggest you could also update the documentation regarding this... it is pretty common use case.
http://web.archive.org/web/20101010142032/http://collective-docs.plone.org/content/creating.html
After several unsuccessful attempts at tweaking _allowedTypes(), I followed the last suggestion at http://plone.org/documentation/kb/restrict-addable-types and customized getNotAddableTypes.py. My customization merely lists a folder's contents filtering for the three ranges. If the resulting array is not empty, I add the three range types to the list:
# customize this script to filter addable portal types based on
# context, the current user or other criteria
ranges = []
ranges = context.listFolderContents(contentFilter={'portal_type':
('VectorRange','ValueRange','UniformRange')})
return {True: ('Favorite', 'VectorRange', 'ValueRange', 'UniformRange'),
False: ('Favorite')}[len(ranges)]
See the last post here for two possibilities: http://plone.293351.n2.nabble.com/Folder-constraints-not-applicable-to-custom-content-types-td6073100.html
The method
foo.getLocallyAllowedTypes()
gives back a tuple, that you just have to copy / filter into another tuple / list, because it's immutable.
allowed_types = parent.getLocallyAllowedTypes()
filtered_types = []
for v in allowed_types:
if not v in ranges:
filtered_types.append(v)
Then you can just give that tuple to the setter method
parent.setLocallyAllowedTypes(filtered_types)
and your're done. But if you want to access the parent during object creation to restrict content types of the folder, you creating the object in, you can hook up in at_post_create_script() and manage_beforeDelete() from BaseObject. This works great for me, restricting the number of specific content types to a folder and also corrects the AllowedTypes when the object gets deleted.

Resources