I want to solve a set of coupled equations using weak form of Comsol. Some tuitials are available for solve simple uncoupled equations using weak form in comsol, which doesn't seem to work for my case.
The equations may look like this (just a simplified form for an example),
r^2*(d^2T/dr^2)+3*r*(dT/dr)+Eh/2*(dw/dr)^2=0
B*(d^2/dr^2+1/r*d/dr)^2w-T*(d^2w/dr^2)-1/r*(dw/dr)*d/dr(r*T)=p
Note: I am aware that the ODEs above may be solve by some other special Modules, but they are just a basic example. I am trying to learn how to solve coupled equations using weak form Module, so that I can solve more complicated equations.
Any suggestions would be appreciated.
Related
I am using PySCIPOpt and have a MIP with some quadratic constraints (works). Now, I want to implement a Primal Heuristic (should run once before presolving), that fixes certain Variables and optimizes afterwards.
Ìn pseudo-code something like:
For x in ToFIX:
model.fixVar(x, my_guess(x))
model.optimize()
*Any found solution is used as solution of the original problem*
For x in ToFIX:
model.unFixVar(x)
I worked around that problem by creating a second model, solving that, identifying the variables by their name and using model.trySol().
This mostly works but is slow and certainly not the way it is meant to be implemented.
Any hint, which functionalities to use is appreciated.
sorry this took a while to answer.
What you want to implement is a sub-scip heuristic. This is certainly possible, but if you want to do it in PySCIPOpt you might have to wrap some missing methods from the C-API.
I suggest you take a look at heur_rens.c in the SCIP code. The methods you would need to wrap are probably SCIPcopyLargeNeighborhoodSearch and SCIPtranslateSubSol which should save you a lot of trouble. Please refer to the section extending the interface in the PySCIPopt Readme.
I found some information about this but I have several confusion regarding this. So when we need to use this RX.NET.
What are the important of using this items? When I need to use this?
As with every toolset, it can shape how you approach problems. Given a hammer, all your problems may become nails. It is the same with Rx.NET. It gives you a new approach. Whether you choose to use this approach for a particular problem is up to you, and as with any tool or technology, there are plusses and minuses. You will need to study and gain experience to make those sort of complex judgements for yourself.
For starters, Rx.NET allows you to cultivate the approach of programming 'reactively.' This is akin to functional programming, in the sense that you declare behavour as being composed of underlying behavior. Rx.NET allows you to specify functions over streams to give new streams. This powerful technique can be applied to almost any problem you can imagine.
For example, a program using Linq and Rx.NET to draw mouse movements as points on a screen within a bounding box would like something like:
mouseMovements.Where(box.Contains(m)).Subscribe(DrawPoint)
where mouseMovements would be your mouse event as an observable
You could declare the
myPointsInBox = mouseMovements.Where(box.Contains(m))
as its own observable and have multiple subscribers:
myPointsInBox.Subscribe(DrawPoint)
myPointsInBox.Subscribe(ConnectWithLines)
myPointsInBox.Subscribe(UpdatePointCounter)
you can make streams from streams
var everyThousandthPoint= myPointsInBox.Buffer(….).Select(…)
and then do things with them
everyThousandthPoint.Subscribe(FlashPointCounter)
You get the idea.
I have a enum based and complicated structure. I want to change my structure with object oriented structure. You must know this there are too much states. So I searched in Internet and I found solutions like that
http://blogs.microsoft.co.il/gilf/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements/,
Ways to eliminate switch in code .
When I apply this solutions, there will be too much classes. What do you think about it, Should I apply like that.
Yes, definitely. You should go for the Strategy solution.
And in my experience, there is almost never a case of too much classes, as you put it. On the contrary, the more modular your code is, the easier it is to test/maintain/deploy it.
You'll run a lot in the opposite problem: a class you thought is small enough and there will be no reason to change, and then after a change in the requirements or a refactoring you see that you need to make it more modular.
I am kind of new to the SCIP. I want to use SCIP as a branch and price framework. I have coded the problem in C++ already and also have implemented the pricer or column generation as a function. In fact I have implemented the BP algorithm for the root node by linking Cplex.dll to the project and now need to code the branching tree and decided to use SCIP for this purpose.
I want to know what is the fastest way I can solve my problem using SCIP and the old codes which I have? Or maybe using GCG is a better and faster way?
I have read the GCG documentation but doesn't understand if I should implement the pricer myself again or not? In fact I don't understand the difference between these two (SCIP and GCG).
Thanks.
In GCG, you do not need to implement anything yourself. It is a generic solver for branch-and-price. You have to provide the compact formulation, that is, a model which after applying a Dantzig-Wolfe reformulation leads to the master problem you are solving. The reformulation also provides a MIP-formulation of the pricing problem, so GCG can solve this as a sub-MIP for pricing. There is the possibility, however, to plug-in a pricing solver in GCG, to which the pricing MIP to be solved will be passed (with objective function corresponding to the current pricing round). The pricing solver can then solve this problem with any problem-specific algorithm and pass solutions back to GCG.
In SCIP, on the other hand, you create the master problem you want to solve and implement a pricer which gets dual values from the LP and solves the corresponding pricing problem. This is probably very similar to what you have already.
Additionally, if you want to do branch-and-price, you need a branching rule. GCG comes with some generic ones, in SCIP you would have to implement one yourself (since the branching decisions must be regarded within your pricing procedure).
Overall, SCIP is a framework for branch-and-price, i.e., it provides the tree management, LP solving and updates, etc., but you need to implement some things yourself like a reader, the pricer, and the branching rules. GCG is a generic solver, so you can just plug in a compact model, which is reformulated and solved in a generic way. The reformulation is either provided by you via an input file or you can try to let GCG detect an appropriate structure. You do not need to implement anything. It already provides some nice features like primal heuristics that make use of the reformulation, an automatic management of which pricing problem is solved when, and more. On the other hand, the possibilities to extend it further, e.g., by a pricing solver and branching rules are restricted compared to SCIP, since you have to stick to the structure defined by GCG.
I would say that using SCIP and adding your pricer is probably the easier way and more similar to what you already have (you do not need to formulate the compact model). If you already have an idea on how your branching should work, it should also not be too hard to implement within SCIP.
I recently got assigned a task to convert a few algorithms written in matlab to VB.NET (or C# if VB.NET isn't efficient).
The matlab code itself consists of a lot of matrix algebra. I initially looked through here and found there was a Matlab Coder that wrapped the matlab code but when I presented that option I was told it isn't desirable.
I am stuck in a sense that I don't know how to approach this with the proper tools.
Is it normally acceptable to grab libraries (http://www.codeproject.com/Articles/5835/DotNetMatrix-Simple-Matrix-Library-for-NET or http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=907&lngWId=10, these are the only ones I could find) to implement these algorithms or is that generally frowned upon?
Do I need to reinvent the wheel and implement my own algorithms for the algebra (matrix multiplication, choleksy decomposition etc)?
Basically, I am not sure what the accepted way of accomplishing this task is, any input would be appreciated. I apologize if this isn't allowed in here, this is my first time posting but I am a long time lurker.
You have several possibilities.
If your application can bear the loading time of MCR, you can use Matlab .NET Builder. It will compile a .NET class, which will run MCR silently underneath. All of your clients will be forced to install MCR on their computer.
If your code must be native you can either rewrite the code, or use Matlab Coder, which will convert the code into unreadable, native c++ code.
If you choose to rewrite the code, I would recommend finding an implementation of LAPACK linear algebra routines on .NET, as Matlab is based on them.
Code like that is published so it can be used and learned from. Just make sure the code's license (if any) is acceptable for your situation.
You can access Matlab functions from VB.net through COM interface
http://www.mathworks.com/help/matlab/matlab_external/view-matlab-functions-from-visual-basic-object-browser.html