|
[Sponsors] |
June 19, 2014, 08:54 |
groovyBC and probe measurement
|
#1 |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
Hi,
I'm trying to use groovyBC to implement closed-loop control in a simulation. I have a probe (in the controlDict) set to record a pressure measurement at a particular position in the geometry, and wish to use this value in conjunction with groovyBC to perform some maths operation on the value of pressure at the probe at each timestep, and use this value to update the value of a particular boundary condition for the next timestep. So far my thinking takes me thus far: Code:
actuatorBoundary { type groovyBC; valueExpression "0.5*(probeReading)"; // Some function of the probe recording variables "probeReading *** NOT SURE HOW TO DO THIS? *** value uniform (0 0 0); } Thanks a lot, Olie |
|
June 19, 2014, 09:15 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
June 20, 2014, 07:49 |
|
#3 | |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
Quote:
Okay so after some more reading and re-reading I think, after I've got a cloud sample correct, the groovyBC boundary in the 0/U file should look something like this: Code:
actuator { type groovyBC; variables "pMeasurement@cloudSampler=p;" valueExpression "10*p"; // Or *SOME* mathematical expression value uniform (1 0 0); // Or *SOME* initial conditions } Thanks again, Olie ****EDIT**** Oh no - found some documentation on using cloud and it appears you can only use this in sampleDict - so now I'm confused.. How do I use this during runtime so it samples (like a probe) at each time step such that groovyBC can then use the value? |
||
June 20, 2014, 12:50 |
|
#4 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
June 23, 2014, 11:35 |
|
#5 | |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
Quote:
Code:
functions { readpField { type readAndUpdateFields; fields ( p ); } createMeasurement { type createSampledSet; outputControl outputTime; outputInterval 1; setName sensor1; set { type cloud; axis x; points ( (0 -0.5 0.5) ); } } } Code:
expressions ( buildP { field p; create true; } ); Field p does not exist From function Foam::readAndUpdateFields::read(const dictionary& dict) in file misc/readAndUpdateFields/readAndUpdateFields.C at line 128. FOAM exiting What am I doing wrong? Thanks again, Olie |
||
June 27, 2014, 15:22 |
|
#6 |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
? Anyone?
|
|
July 1, 2014, 13:26 |
Working (I think) but strange results.
|
#7 |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
I believe I've got it working now - I put this in the functions section of the controlDict:
Code:
createMeasurement { type createSampledSet; outputControl outputTime; outputInterval 1; setName sensor1; set { type cloud; axis xyz; points ( (0 -0.5 0.5) ); } } Code:
actuator { type groovyBC; value uniform (0 0 0); variables ( "pressureMeasurement{set'sensor1}=p;" ); valueExpression "0.01*vector(0,pressureMeasurement,0)"; } I think it's *close* to working, but not quite. The attached image (hope the attaching works) shows the sampled pressure from sensor1, p_wall, the velocity on the actuator boundary v_act, and the ratio of p_wall to v_wall, which *should* be 100, given groovyBC is set to give v_act=0.01*p_wall, but it's more like 200. Am I doing something wrong? Thanks! |
|
July 2, 2014, 18:45 |
|
#8 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
BTW: just to be sure make it "pressureMeasurement{set'sensor1}=average( p );" (I think otherwise it might break in parallel)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
July 3, 2014, 05:48 |
|
#9 | |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
Quote:
Code:
actuator_velocity { type uniform; axis z; start (-0.015 0 0); end (-0.015 0 1); nPoints 3; } Oh thank you I'll put in average(). Also, can you use matrices in groovyBC expressions? Similar to how you can use vectors somehow? If so how do you do this? Thanks a lot. Last edited by odellar; July 3, 2014 at 07:37. Reason: Additional question added |
||
July 3, 2014, 09:16 |
Also...
|
#10 |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
Also, I'm using some storedVariables for a boundary condition, which update themselves each timestep, something like storedVariable1 = 0.5*storedVariable1 (there's more to it, but that's the general idea). However my thinking is that it updates the value of the variable every computational timestep which is a variable time step - I only want it to update at every write interval - so how do I specify that it's only to update at, for example, every 0.5 seconds? NOT ever actual computational time step?
Thanks a lot again, Olie |
|
July 3, 2014, 16:22 |
|
#11 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
matrixes are called tensors (3x3). swak supports all the operations on them OF supports (see the programmers-guide)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
July 3, 2014, 16:30 |
|
#12 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
You want your storedVariable1 to "decay" exponentially, right? A bit of fiddling around with deltaT() and exp() will give you a decay with the same rate (it is year 1 mathematics. So don't ask me for formulas. I don't want to embarrass myself)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
July 4, 2014, 07:32 |
|
#13 | |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
Quote:
No that was just an example of the manner in which I'm wanting to use storedVariables - what I'm trying to do with them is actually more complicated, using them as state values for a discrete time state-space controller. But this shouldn't matter - the point is I need it to only update storedVariables at certain times: the times when data is written. Correct the solution will depend on how often it's written - this is CORRECT in my particular situation (don't ask why, unless you're really interested!). So is this possible? Thank you for all your help so far! I dare say I'm at the final hurdle! |
||
July 5, 2014, 07:52 |
|
#14 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
General swak-Expressions have no function "outputTime()" that is true for times when OF does output (for the reasons above). What DOES have such a variable is the Python-integration
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
July 7, 2014, 05:51 |
|
#15 | |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
Quote:
Thanks, Olie |
||
July 9, 2014, 15:05 |
|
#16 |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
No. That is for common expressions between BCs (mostly for "smoothing" what goes out on one side to be used as input on the other side). Variables for the state are declared in system/controlDict in the defineState functionObject.
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
|
July 14, 2014, 08:46 |
|
#17 | |
Member
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 13 |
Quote:
My guess is to put something like this in controlDict: Code:
defineState { type addGlobalVariable; outputControl runtime; outputInterval 0.5; // to output every 0.5 seconds? globalScope stateInformation; globalVariables { state1 { valueType scalar; value 0; // What does this mean? } state2 { valueType scalar; value 0; // What does this mean? } } } If it helps, the attached image shows what I'm trying to implement - note that state values x do not refer to some physical state (such as pressure, velocity etc), they're just values that are updated at each write interval according to x_k+1 = Ax_k + Bs_k, and in the image when I refer to 'timestep' I also mean write interval, i.e. some fixed interval (in my case 0.5 seconds). Thanks |
||
July 22, 2014, 17:43 |
|
#18 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Anyway: For the meaning of value etc see http://openfoamwiki.net/images/c/c0/...rogrammers.pdf starting at page 30. A few pages later calculateGlobalVariables is explained (which would be how you get the sensor values). The groovyBC then will only have to get the global variables (that is also explained there)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
Tags |
groovybc, probe pressure |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] Error using groovyBC - 'parser error for expression driver' | odellar | OpenFOAM Community Contributions | 4 | September 21, 2015 12:51 |
[swak4Foam] groovyBC and probe problem, needing your help! | wwbbit | OpenFOAM Community Contributions | 4 | April 17, 2010 01:31 |