CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[swak4Foam] Using lookuptables in momentumSourceDict with swak4Foam

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 29, 2012, 16:53
Default Using lookuptables in momentumSourceDict with swak4Foam
  #1
New Member
 
Hugo
Join Date: Jan 2011
Location: Montreal
Posts: 27
Rep Power: 15
Hugoles is on a distinguished road
Hello,

I am trying to define a transient momentum source using swak4foam. Using expressionSource and modifying the solver, I can define the source value with a dictionary. The issue here is that I need to look up values in a table to evaluate the source expression, so I would like to know if this is possible.

I know that this can be done with groovyBC, so I tried to do it as in the wobbler example. What I have in my momentumSourceDict is something like:

Code:
UEqn {
  variables (
      "r=sqrt(pow(pos().z,2)+pow(pos().y,2));"
       "phi=atan((U.component(0))/pos().y);"
       "alpha=phi-twist(r);"
       "f=cl(alpha)*cos(phi);"
                    );
  
  expression  "pow(pos().y,2) < pow(0.5,2) ? f : 0";

  lookuptables (
      {
        name twist;
        outOfBounds clamp ;
        filename "$FOAM_CASE/constant/twist.data" ;
      }
        );
  
  lookuptables (
      {
        name cl;
        outOfBounds clamp ;
        filename "$FOAM_CASE/constant/cl.data" ;
      }
        );
...
When I try to run this I get the error:

Code:
keyword fileName is undefined in dictionary ""

file:  from line 56 to line 58.

    From function dictionary::lookupEntry(const word&, bool, bool) const
    in file db/dictionary/dictionary.C at line 388.

FOAM exiting
where lines 56 to 58 are those of "name" to "filename" in the second "lookuptables" call.

Has someone tried to do something similar with lookuptables in the dictionary of a momentum source??

Also: a) what would be the interpolation scheme used to get the intermediate values from the tables? b) what is the meaning of "clamp" in the entry "outOfBounds"?

thanks!,

h
Hugoles is offline   Reply With Quote

Old   May 29, 2012, 17:51
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hugoles View Post
Hello,

I am trying to define a transient momentum source using swak4foam. Using expressionSource and modifying the solver, I can define the source value with a dictionary. The issue here is that I need to look up values in a table to evaluate the source expression, so I would like to know if this is possible.

I know that this can be done with groovyBC, so I tried to do it as in the wobbler example. What I have in my momentumSourceDict is something like:

Code:
UEqn {
  variables (
      "r=sqrt(pow(pos().z,2)+pow(pos().y,2));"
       "phi=atan((U.component(0))/pos().y);"
       "alpha=phi-twist(r);"
       "f=cl(alpha)*cos(phi);"
                    );
  
  expression  "pow(pos().y,2) < pow(0.5,2) ? f : 0";

  lookuptables (
      {
        name twist;
        outOfBounds clamp ;
        filename "$FOAM_CASE/constant/twist.data" ;
      }
        );
  
  lookuptables (
      {
        name cl;
        outOfBounds clamp ;
        filename "$FOAM_CASE/constant/cl.data" ;
      }
        );
...
When I try to run this I get the error:

Code:
keyword fileName is undefined in dictionary ""

file:  from line 56 to line 58.

    From function dictionary::lookupEntry(const word&, bool, bool) const
    in file db/dictionary/dictionary.C at line 388.

FOAM exiting
where lines 56 to 58 are those of "name" to "filename" in the second "lookuptables" call.
Case is important for OpenFOAM: you write "filename" and OF doesn't understand you because it wants a big N. On the other hand: it tells you so. All you've got to do is listen

Quote:
Originally Posted by Hugoles View Post
Has someone tried to do something similar with lookuptables in the dictionary of a momentum source??
Entries in OF-dictionaries are like the Highlander (the 80s movie): "There can be only one". So you'll probably wanted to write it like this:
Code:
  lookuptables (
      {
        name twist;
        outOfBounds clamp ;
        filename "$FOAM_CASE/constant/twist.data" ;
      }
      {
        name cl;
        outOfBounds clamp ;
        filename "$FOAM_CASE/constant/cl.data" ;
      }
    );
This is the reason why lookuptables is a "list of dictionaries"

Quote:
Originally Posted by Hugoles View Post
Also: a) what would be the interpolation scheme used to get the intermediate values from the tables? b) what is the meaning of "clamp" in the entry "outOfBounds"?
a) linear interpolation (its implemented like this in the OF-core - the most sensible choice in my opinion)
b) if you're outside of the range the table is defined for then the "last valid" value is used
gschaider is offline   Reply With Quote

Old   May 29, 2012, 22:59
Default
  #3
New Member
 
Hugo
Join Date: Jan 2011
Location: Montreal
Posts: 27
Rep Power: 15
Hugoles is on a distinguished road
Ok, I should have read more carefully... it's really cool to see how portable are the utilities from swak4Foam. Great code!

As for the entries, I guess my problem is that when I work with OF, I always have in mind Highlander: The Series and not Highlander (film, which I have not yet seen). In the former, there was a new immortal almost every episode which is not a good example of uniqueness...

I still have one more question about the tables: could I define a table with more than two columns and make lookuptables to search values from an specific column with respect to another particular column? obviously, that will help to avoid to write new data files for each new variable extracted from tables. Even more, what about two tables in one data file??

thanks,

h
Hugoles is offline   Reply With Quote

Old   May 30, 2012, 04:49
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hugoles View Post
Ok, I should have read more carefully... it's really cool to see how portable are the utilities from swak4Foam. Great code!
Thanks. But I'm standing on the shoulders of giants (OpenFOAM) here. And when

Quote:
Originally Posted by Hugoles View Post
As for the entries, I guess my problem is that when I work with OF, I always have in mind Highlander: The Series and not Highlander (film, which I have not yet seen). In the former, there was a new immortal almost every episode which is not a good example of uniqueness...
Well. I'm an eighties-kid. Only the movie is the real thing (and only the first movie: "There can ....")
Quote:
Originally Posted by Hugoles View Post
I still have one more question about the tables: could I define a table with more than two columns and make lookuptables to search values from an specific column with respect to another particular column? obviously, that will help to avoid to write new data files for each new variable extracted from tables. Even more, what about two tables in one data file??
Not using the original OpenFOAM-syntax (and swak uses the OF-mechanism for reading these files).

But for some time OF can read CSV-files. The only "documentation" about this that I know of are the notes of the original patch submission:
http://www.openfoam.org/mantisbt/view.php?id=97
I guess with that you should be able to do that
elvis likes this.
gschaider is offline   Reply With Quote

Old   July 4, 2012, 23:18
Default
  #5
New Member
 
Hugo
Join Date: Jan 2011
Location: Montreal
Posts: 27
Rep Power: 15
Hugoles is on a distinguished road
Hello Bernhard,

I come back to this threat as I have been dealing with some new issues when working with a momentumSourceDict (thanks for all your help so far!). I hope that you (or someone else) can help me to figure this:

1) In my code, I need to obtain the length of the cell in one specific direction. There are a couple of threads discussing how to deal with this in OF that imply programming, which takes me out of the swak world. I was under the impression (so probably erroneous) that in swak I could use something like "mag(pts().x)" but every time I try to use it I get :
Code:
swak4Foam: Allocating new repository for sampledGlobalVariables


 Parser Error at "1.5-7" :"field pts not existing or of wrong type"
"mag(pts().x)"
"     ^^^    "

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 724.

FOAM exiting
I see in the examples of groovyBC that this function is used (also in the README). Is this syntaxis unsupported for this particular library or am I missing something? Is there any other way to calculate the cell length?

2) In my calculations I have to calculate a variable that depends on other two. The problem is that both relations are given by tables. Therefore, I think I need to do something like defining a table with values that are in turn variables whose dependency is looked up in another table (hope this makes sense ). Is there anything in swak that can be useful in this case?

3) This is a very general question: I define a large number or variables in my momentumSourceDict, most of them being actual calculations instead of just constants. In the end, I will only use all those computations within a small region of my domain that I define with a condition in the expression entry. I wonder if swak (or openFoam) will perform the calculations for ALL the cells in the domain or only within the defined region. I am almost certain that in such logical expressions the condition will be checked before calling the variables to evaluate the expression, but I want to be sure (my code is running a bit slow). Any advice for "good practices" in swak when many calculations have to be performed to calculate the momentum source (other than doing everything in the variables entry)?

I very much appreciate any help with this, thanks!

Hugo
Hugoles is offline   Reply With Quote

Old   July 5, 2012, 04:55
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hugoles View Post
Hello Bernhard,

I come back to this threat as I have been dealing with some new issues when working with a momentumSourceDict (thanks for all your help so far!). I hope that you (or someone else) can help me to figure this:
Of course one shouldn't smile about other people's typos (especially if one does as many as I do), but you totally lightened up my day: you meant thread, didn't you?

Quote:
Originally Posted by Hugoles View Post
1) In my code, I need to obtain the length of the cell in one specific direction. There are a couple of threads discussing how to deal with this in OF that imply programming, which takes me out of the swak world. I was under the impression (so probably erroneous) that in swak I could use something like "mag(pts().x)" but every time I try to use it I get :
Code:
swak4Foam: Allocating new repository for sampledGlobalVariables


 Parser Error at "1.5-7" :"field pts not existing or of wrong type"
"mag(pts().x)"
"     ^^^    "

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 724.

FOAM exiting
I see in the examples of groovyBC that this function is used (also in the README). Is this syntaxis unsupported for this particular library or am I missing something? Is there any other way to calculate the cell length?
Which parser are we talking about? Field, Patch, CellSet, .... pts should be available in all of them although only Field and Patch currently properly support it.

"mag(pts().x)" works for me in funkySetFields but yields a pointScalarField (not surprisingly)

Currently there is no such function to calculate the length of a cell. The only thing similarly is fproj which does the same thing for faces (I think it was discussed some years ago when it was added). Maybe that might help you

I'm currently working on an extension to swak that allows "plugin functions" that allow to dynamically adding such eccentric functions (by loading a library) without polluting the general parser. But don't expect it to be released in the next few weeks

Quote:
Originally Posted by Hugoles View Post
2) In my calculations I have to calculate a variable that depends on other two. The problem is that both relations are given by tables. Therefore, I think I need to do something like defining a table with values that are in turn variables whose dependency is looked up in another table (hope this makes sense ). Is there anything in swak that can be useful in this case?
You mean something like "cp(T(p))"? Nesting lookup-tables should work

Quote:
Originally Posted by Hugoles View Post
3) This is a very general question: I define a large number or variables in my momentumSourceDict, most of them being actual calculations instead of just constants. In the end, I will only use all those computations within a small region of my domain that I define with a condition in the expression entry. I wonder if swak (or openFoam) will perform the calculations for ALL the cells in the domain or only within the defined region. I am almost certain that in such logical expressions the condition will be checked before calling the variables to evaluate the expression, but I want to be sure (my code is running a bit slow). Any advice for "good practices" in swak when many calculations have to be performed to calculate the momentum source (other than doing everything in the variables entry)?
I'm sorry. The expressions are calculated EVERYWHERE. Everything else would mean reimplementing half of the functionality of OF because swak for instance calls fvc::grad when it sees a "grad(T)". I'm sorry. There is a price one has to pay for the convenience: CPU-time. The question is: how much is this compared to the pressure-Equation (usually the one that takes longest). But this was also one of the reasons I introduced variables: to at least allow the user to avoid calculating common subexpressions twice
gschaider is offline   Reply With Quote

Old   July 5, 2012, 18:41
Default
  #7
New Member
 
Hugo
Join Date: Jan 2011
Location: Montreal
Posts: 27
Rep Power: 15
Hugoles is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Of course one shouldn't smile about other people's typos (especially if one does as many as I do), but you totally lightened up my day: you meant thread, didn't you?
Always glad to help people smile.. yeah, certainly didn't mean to threat anybody

Quote:
Originally Posted by gschaider View Post
Which parser are we talking about? Field, Patch, CellSet, .... pts should be available in all of them although only Field and Patch currently properly support it.

"mag(pts().x)" works for me in funkySetFields but yields a pointScalarField (not surprisingly)

Currently there is no such function to calculate the length of a cell. The only thing similarly is fproj which does the same thing for faces (I think it was discussed some years ago when it was added). Maybe that might help you

I'm currently working on an extension to swak that allows "plugin functions" that allow to dynamically adding such eccentric functions (by loading a library) without polluting the general parser. But don't expect it to be released in the next few weeks
I am trying to calculate the cell length within the momentumSourceDict (in fact all my questions are regarding definitions there) so from your answer to the last question, I suppose the parser should be Field. Could it be that it is only working on funkySetFields and not with an expression source?

When using mag(fproj().x), each iteration I get the message:

Code:
  --> FOAM Warning : 
    From function CommonValueExpressionDriver::getOrReadField(const string &name)
    in file lnInclude/CommonValueExpressionDriverI.H at line 479
    The minimum value 0 and the maximum 0.237249 differ. I will use the average 0.0653528
smoothSolver:  Solving for Ux, Initial residual = 0.0157376, Final residual = 2.49653e-06, No Iterations 2
smoothSolver:  Solving for Uy, Initial residual = 0.17203, Final residual = 6.2864e-06, No Iterations 2
smoothSolver:  Solving for Uz, Initial residual = 0.170779, Final residual = 4.71258e-06, No Iterations 2
GAMG:  Solving for p, Initial residual = 0.227005, Final residual = 0.00115162, No Iterations 4
time step continuity errors : sum local = 5.43288e-09, global = -4.06776e-10, cumulative = -1.03195e-09
--> FOAM Warning : 
    From function CommonValueExpressionDriver::getOrReadField(const string &name)
    in file lnInclude/CommonValueExpressionDriverI.H at line 479
    The minimum value 0 and the maximum 0.237249 differ. I will use the average 0.0653528
GAMG:  Solving for p, Initial residual = 0.0328788, Final residual = 0.000162776, No Iterations 4
time step continuity errors : sum local = 1.0129e-09, global = -2.21125e-10, cumulative = -1.25308e-09
--> FOAM Warning : 
    From function CommonValueExpressionDriver::getOrReadField(const string &name)
    in file lnInclude/CommonValueExpressionDriverI.H at line 479
    The minimum value 0 and the maximum 0.237249 differ. I will use the average 0.0653528
ExecutionTime = 8.98 s  ClockTime = 10 s
I expect the code to calculate the length of the current cell (or face mag), so it is interesting that it warns me from the fact of having more than one value

Quote:
Originally Posted by gschaider View Post
You mean something like "cp(T(p))"? Nesting lookup-tables should work
Not quite: My variable depends on another two but they are not nested (using your example, cp would depend on T and p (more like cp(T,p) ) but T won't be a function of p). I tried to define a table with functions but it didn't work, e.g. a table containing data for cd18(r) would have lines of the sort

( 39.119 cd18(alpha) )

but this gives me

Code:
wrong token type - expected Scalar found on line 27 the word 'cl18(alpha)'
looks like it is expecting and scalar and nothing else. What do you think?


Quote:
Originally Posted by gschaider View Post
I'm sorry. The expressions are calculated EVERYWHERE. Everything else would mean reimplementing half of the functionality of OF because swak for instance calls fvc::grad when it sees a "grad(T)". I'm sorry. There is a price one has to pay for the convenience: CPU-time. The question is: how much is this compared to the pressure-Equation (usually the one that takes longest). But this was also one of the reasons I introduced variables: to at least allow the user to avoid calculating common subexpressions twice
Everything is very convenient, one can hardly ask for more! However, I have the feeling (but no more than that) that there should be a work around. I tried to assign a condition to each variable definition to write zeros outside the region of interest, hoping that that would avoid the calculations (and memory allocation) at those cells. That did not seem to improve the speed of computation. Will it be possible to use the momentum source only in a cellSet ? Alternatively, If I wrote a condition in the solver to add the momentum source only in a region, will the variables defined in a dictionay will still be calculated everywhere??

Thanks for all you help,

h
Hugoles is offline   Reply With Quote

Old   July 16, 2012, 12:47
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hugoles View Post
Always glad to help people smile.. yeah, certainly didn't mean to threat anybody



I am trying to calculate the cell length within the momentumSourceDict (in fact all my questions are regarding definitions there) so from your answer to the last question, I suppose the parser should be Field. Could it be that it is only working on funkySetFields and not with an expression source?

When using mag(fproj().x), each iteration I get the message:

Code:
  --> FOAM Warning : 
    From function CommonValueExpressionDriver::getOrReadField(const string &name)
    in file lnInclude/CommonValueExpressionDriverI.H at line 479
    The minimum value 0 and the maximum 0.237249 differ. I will use the average 0.0653528
smoothSolver:  Solving for Ux, Initial residual = 0.0157376, Final residual = 2.49653e-06, No Iterations 2
smoothSolver:  Solving for Uy, Initial residual = 0.17203, Final residual = 6.2864e-06, No Iterations 2
smoothSolver:  Solving for Uz, Initial residual = 0.170779, Final residual = 4.71258e-06, No Iterations 2
GAMG:  Solving for p, Initial residual = 0.227005, Final residual = 0.00115162, No Iterations 4
time step continuity errors : sum local = 5.43288e-09, global = -4.06776e-10, cumulative = -1.03195e-09
--> FOAM Warning : 
    From function CommonValueExpressionDriver::getOrReadField(const string &name)
    in file lnInclude/CommonValueExpressionDriverI.H at line 479
    The minimum value 0 and the maximum 0.237249 differ. I will use the average 0.0653528
GAMG:  Solving for p, Initial residual = 0.0328788, Final residual = 0.000162776, No Iterations 4
time step continuity errors : sum local = 1.0129e-09, global = -2.21125e-10, cumulative = -1.25308e-09
--> FOAM Warning : 
    From function CommonValueExpressionDriver::getOrReadField(const string &name)
    in file lnInclude/CommonValueExpressionDriverI.H at line 479
    The minimum value 0 and the maximum 0.237249 differ. I will use the average 0.0653528
ExecutionTime = 8.98 s  ClockTime = 10 s
I expect the code to calculate the length of the current cell (or face mag), so it is interesting that it warns me from the fact of having more than one value
Could you give me the full context you call the function from?


Quote:
Originally Posted by Hugoles View Post
Not quite: My variable depends on another two but they are not nested (using your example, cp would depend on T and p (more like cp(T,p) ) but T won't be a function of p). I tried to define a table with functions but it didn't work, e.g. a table containing data for cd18(r) would have lines of the sort

( 39.119 cd18(alpha) )

but this gives me

Code:
wrong token type - expected Scalar found on line 27 the word 'cl18(alpha)'
looks like it is expecting and scalar and nothing else. What do you think?
That doesn't work I'm afraid. These tables only accept straight values. And interpolation tables of functions with multiple variables are not THAT trivial to implement I'm afraid

Quote:
Originally Posted by Hugoles View Post
Everything is very convenient, one can hardly ask for more! However, I have the feeling (but no more than that) that there should be a work around. I tried to assign a condition to each variable definition to write zeros outside the region of interest, hoping that that would avoid the calculations (and memory allocation) at those cells. That did not seem to improve the speed of computation. Will it be possible to use the momentum source only in a cellSet ? Alternatively, If I wrote a condition in the solver to add the momentum source only in a region, will the variables defined in a dictionay will still be calculated everywhere??

Thanks for all you help,

h
I'm afraid not. There is a way to do calculations on cellSets in swak but currently there is no way to say "take these values on the cellSet and write them into the original field". Although it is not THAT hard to implement
gschaider is offline   Reply With Quote

Old   July 20, 2012, 17:43
Default
  #9
New Member
 
Hugo
Join Date: Jan 2011
Location: Montreal
Posts: 27
Rep Power: 15
Hugoles is on a distinguished road
Hello Bernhard,

Thank you very much for your response.


Quote:
Originally Posted by gschaider View Post
Could you give me the full context you call the function from?
I am trying to get the cell x-length before doing anything else with it, so there is not really much context. I attempt to define a variable in a way like this:
Code:
UEqn {
  variables (

                "delta=mag(fproj().x);"
                "force=0.5*pow(mag(U),2)*ct/delta;"
                "forceV=vector(force,0,0);"
                "nada=vector(0,0,0);"
                )
  expression "pow(pos().y,2) + pow(pos().z,2) < pow(0.5,2) &&  0<pos().x && pos().x<0.01 ? forceV : nada)";

... etc.
and if I try to define delta using pts().x I get the error mentioned above, which I guess comes from the fact that pts() gives a pointScalarField.

Although it would be very convenient to find a way to calculate the cell length, I can use a workaround (like writing the cell lengths explicitly). On the other hand, I have a more general issue I would like to ask you about. Sorry to keep posting question after question, I really appreciate your help!

The question is: does is exist a way in swak to define an array, either of scalars or vectors? I am not mistaken, this can be done in openFOAM using lists, but I just can't find the way to do it in swak. I have checked some Libraries (e.g. swakFiniteArea/FaPatchValueExpressionParser.yy) looking for definitions that could represent arrays but I found nothing I could recognize. I need arrays of vectors to perform operations of the type one would perform using a FOR loop. So far my solution has been to nest IF THEN ELSE loops which evidently is the most atrocious resort.

I suppose this could also be accomplished using the new function codedFunctionObject with global variables to introduce some programming (although I still use OF 1.6 !). Nonetheless, could I define arrays in "pure" swak?

Thank you very much again,

Hugo
Hugoles is offline   Reply With Quote

Old   July 31, 2012, 15:59
Arrow
  #10
New Member
 
Hugo
Join Date: Jan 2011
Location: Montreal
Posts: 27
Rep Power: 15
Hugoles is on a distinguished road
I still haven't found how to manipulate arrays with swak. I have moved to OF 2.1.x and the latest swak4Foam (svn, not developing) to try to do it with either swakCoded or pythonIntegration and none of them seem to work. I can't really see where the error is.

using pythonIntegration, I define:

Code:
    polarMesh
    {
        type pythonIntegration;
        startFile "$FOAM_CASE/polarMesh.py";
        executeCode "";
        endCode "";
        pythonToSwakNamespace polarMeshVariables;
        pythonToSwakVariables ( rPolArray);
        parallelMasterOnly true;
     }
and in polarMesh.py :
Code:
from numpy import *
Radius = 46.5
rNvalues = 10
rPolArray = zeros(rNvalues)
for i in range(0,rNvalues):
    rPolArray[i] = array(Radius*i/(rNvalues-1))
and I get the following error:
Code:
Starting time loop

Reading/calculating field UMean

fieldAverage: starting averaging at time 0

swak4Foam: Setting default mesh
swak4Foam: Allocating new repository for sampledGlobalVariables
#0  Foam::error::printStack(Foam::Ostream&) in "/home/holivares/OpenFOAM/OpenFOAM-2.1.x/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1  Foam::sigSegv::sigHandler(int) in "/home/holivares/OpenFOAM/OpenFOAM-2.1.x/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2   in "/lib/x86_64-linux-gnu/libc.so.6"
#3  Foam::pythonInterpreterWrapper::setGlobals() in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/lib/libpythonIntegration.so"
#4  Foam::pythonInterpreterWrapper::doAfterExecution(bool, Foam::string const&, bool, bool) in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/lib/libpythonIntegration.so"
#5  Foam::pythonInterpreterWrapper::executeCode(Foam::string const&, bool, bool) in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/lib/libpythonIntegration.so"
#6  Foam::pythonIntegrationFunctionObject::start() in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/lib/libpythonIntegration.so"
#7  Foam::functionObjectList::read() in "/home/holivares/OpenFOAM/OpenFOAM-2.1.x/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#8  Foam::Time::run() const in "/home/holivares/OpenFOAM/OpenFOAM-2.1.x/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#9  
 in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/bin/vForceFoamATSwakSource"
#10  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#11  
 in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/bin/vForceFoamATSwakSource"
Segmentation fault (core dumped)
The error appears when I try to export the python variable that contains the array into swak, as the code runs fine as long as I do not call "rPolArray" in the pythonToSwakVariables. This makes me wonder if I am missing something (maybe very basic) about manipulation of arrays in swak and/or OF.

Similarly, when I use swakCoded:

Code:
    polarMesh
    {
        functionObjectLibs ("libswakFunctionObjects.so");
        type swakCoded;
        ///codedToSwakNamespace polarMeshVariables;
        ///codedToSwakVariables ( rPolArray );
        //verboseCode true;
        code
        #{
            Info<< "Define polar arrays rPolar & theta\n" << endl;
        const double Radius = 45.5;
        const int rNvalues = 10;       
        scalar rPolArray[] = { 0 }; 
        for (int i=0; i<rNvalues; i++)
          {
          rPolArray[i]=Radius*i/(rNvalues-1);
          }
        cout << "rPolArray is=" << rPolArray << endl;
    #};
    }
if I do not attempt to export the variable "rPolArray" (as above), I only get the warning:

Code:
Starting time loop

Reading/calculating field UMean

fieldAverage: starting averaging at time 0

swak4Foam: Setting default mesh
swak4Foam: Allocating new repository for sampledGlobalVariables
Using dynamicCode for functionObject polarMesh at line 339 in "/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh"
Creating new library in "dynamicCode/_a43832a4c92be3f67897563bacc2c678008661f2/platforms/linux64GccDPOpt/lib/lib_a43832a4c92be3f67897563bacc2c678008661f2.so"
Invoking "wmake -s libso /home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/dynamicCode/_a43832a4c92be3f67897563bacc2c678008661f2"
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file functionObjectTemplate.C
Making dependency list for source file FilterFunctionObjectTemplate.C
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh: In member function ‘virtual void Foam::FunctionObject::write()’:
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:20:42: warning: array subscript is above array bounds [-Warray-bounds]
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:20:19: warning: array subscript is above array bounds [-Warray-bounds]
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:20:19: warning: array subscript is above array bounds [-Warray-bounds]
'/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/dynamicCode/_a43832a4c92be3f67897563bacc2c678008661f2/../platforms/linux64GccDPOpt/lib/lib_a43832a4c92be3f67897563bacc2c678008661f2.so' is up to date.
Time = 0
...
but the code seems to run fine. In turn, when I try to export that variable (into the namespace polarMeshVariables):

Code:
Starting time loop

Reading/calculating field UMean

fieldAverage: starting averaging at time 0

swak4Foam: Setting default mesh
swak4Foam: Allocating new repository for sampledGlobalVariables
Using dynamicCode for functionObject polarMesh at line 339 in "/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh"
Creating new library in "dynamicCode/_9dbdf78941043e646b703baa5235446b127c8dcb/platforms/linux64GccDPOpt/lib/lib_9dbdf78941043e646b703baa5235446b127c8dcb.so"
Invoking "wmake -s libso /home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/dynamicCode/_9dbdf78941043e646b703baa5235446b127c8dcb"
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file functionObjectTemplate.C
Making dependency list for source file FilterFunctionObjectTemplate.C
In file included from /home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/bool.H:58:0,
                 from /home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/UList.H:45,
                 from /home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/List.H:43,
                 from /home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/stringList.H:42,
                 from functionObjectTemplate.H:36,
                 from functionObjectTemplate.C:26:
/home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/pTraits.H: In instantiation of ‘Foam::pTraits<double [1]>’:
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:32:117:   instantiated from here
/home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/pTraits.H:51:7: error: base type ‘double [1]’ fails to be a struct or class type
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh: In member function ‘virtual void Foam::FunctionObject::write()’:
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:32:117: error: no matching function for call to ‘Foam::ExpressionResult::ExpressionResult(Foam::scalar [1])’
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:32:117: note: candidates are:
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:110:5: note: template<class Type> Foam::ExpressionResult::ExpressionResult(const Type&, typename Foam::ExpressionResult::enable_if_rank0<Foam::pTraits<T>::rank>::type*)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:100:5: note: template<class Type> Foam::ExpressionResult::ExpressionResult(const Foam::dimensioned<Type>&)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:96:5: note: template<class Type> Foam::ExpressionResult::ExpressionResult(const Foam::Field<Type>&)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:92:5: note: Foam::ExpressionResult::ExpressionResult(const Foam::dictionary&, bool)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:92:5: note:   no known conversion for argument 1 from ‘Foam::scalar [1] {aka double [1]}’ to ‘const Foam::dictionary&’
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:89:5: note: Foam::ExpressionResult::ExpressionResult(const Foam::ExpressionResult&)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:89:5: note:   no known conversion for argument 1 from ‘Foam::scalar [1] {aka double [1]}’ to ‘const Foam::ExpressionResult&’
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:86:5: note: Foam::ExpressionResult::ExpressionResult()
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:86:5: note:   candidate expects 0 arguments, 1 provided
make: *** [Make/linux64GccDPOpt/functionObjectTemplate.o] Error 1


--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/_9dbdf78941043e646b703baa5235446b127c8dcb/platforms/linux64GccDPOpt/lib/lib_9dbdf78941043e646b703baa5235446b127c8dcb.so"


file: /home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh from line 339 to line 0.

    From function codedBase::createLibrary(..)
    in file db/dynamicLibrary/codedBase/codedBase.C at line 202.

FOAM exiting
although I have to admit that I might have ill-defined something in the C++ code (although I tried different definitions of the array and none seem to worked) .

What am I doing wrong?

Thank you very much,

h
Hugoles is offline   Reply With Quote

Old   August 6, 2012, 19:22
Default
  #11
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hugoles View Post
I still haven't found how to manipulate arrays with swak. I have moved to OF 2.1.x and the latest swak4Foam (svn, not developing) to try to do it with either swakCoded or pythonIntegration and none of them seem to work. I can't really see where the error is.

using pythonIntegration, I define:

Code:
    polarMesh
    {
        type pythonIntegration;
        startFile "$FOAM_CASE/polarMesh.py";
        executeCode "";
        endCode "";
        pythonToSwakNamespace polarMeshVariables;
        pythonToSwakVariables ( rPolArray);
        parallelMasterOnly true;
     }
and in polarMesh.py :
Code:
from numpy import *
Radius = 46.5
rNvalues = 10
rPolArray = zeros(rNvalues)
for i in range(0,rNvalues):
    rPolArray[i] = array(Radius*i/(rNvalues-1))
and I get the following error:
Code:
Starting time loop

Reading/calculating field UMean

fieldAverage: starting averaging at time 0

swak4Foam: Setting default mesh
swak4Foam: Allocating new repository for sampledGlobalVariables
#0  Foam::error::printStack(Foam::Ostream&) in "/home/holivares/OpenFOAM/OpenFOAM-2.1.x/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1  Foam::sigSegv::sigHandler(int) in "/home/holivares/OpenFOAM/OpenFOAM-2.1.x/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2   in "/lib/x86_64-linux-gnu/libc.so.6"
#3  Foam::pythonInterpreterWrapper::setGlobals() in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/lib/libpythonIntegration.so"
#4  Foam::pythonInterpreterWrapper::doAfterExecution(bool, Foam::string const&, bool, bool) in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/lib/libpythonIntegration.so"
#5  Foam::pythonInterpreterWrapper::executeCode(Foam::string const&, bool, bool) in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/lib/libpythonIntegration.so"
#6  Foam::pythonIntegrationFunctionObject::start() in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/lib/libpythonIntegration.so"
#7  Foam::functionObjectList::read() in "/home/holivares/OpenFOAM/OpenFOAM-2.1.x/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#8  Foam::Time::run() const in "/home/holivares/OpenFOAM/OpenFOAM-2.1.x/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#9  
 in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/bin/vForceFoamATSwakSource"
#10  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#11  
 in "/home/holivares/OpenFOAM/holivares-2.1.x/platforms/linux64GccDPOpt/bin/vForceFoamATSwakSource"
Segmentation fault (core dumped)
The error appears when I try to export the python variable that contains the array into swak, as the code runs fine as long as I do not call "rPolArray" in the pythonToSwakVariables. This makes me wonder if I am missing something (maybe very basic) about manipulation of arrays in swak and/or OF.

Similarly, when I use swakCoded:

Code:
    polarMesh
    {
        functionObjectLibs ("libswakFunctionObjects.so");
        type swakCoded;
        ///codedToSwakNamespace polarMeshVariables;
        ///codedToSwakVariables ( rPolArray );
        //verboseCode true;
        code
        #{
            Info<< "Define polar arrays rPolar & theta\n" << endl;
        const double Radius = 45.5;
        const int rNvalues = 10;       
        scalar rPolArray[] = { 0 }; 
        for (int i=0; i<rNvalues; i++)
          {
          rPolArray[i]=Radius*i/(rNvalues-1);
          }
        cout << "rPolArray is=" << rPolArray << endl;
    #};
    }
if I do not attempt to export the variable "rPolArray" (as above), I only get the warning:

Code:
Starting time loop

Reading/calculating field UMean

fieldAverage: starting averaging at time 0

swak4Foam: Setting default mesh
swak4Foam: Allocating new repository for sampledGlobalVariables
Using dynamicCode for functionObject polarMesh at line 339 in "/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh"
Creating new library in "dynamicCode/_a43832a4c92be3f67897563bacc2c678008661f2/platforms/linux64GccDPOpt/lib/lib_a43832a4c92be3f67897563bacc2c678008661f2.so"
Invoking "wmake -s libso /home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/dynamicCode/_a43832a4c92be3f67897563bacc2c678008661f2"
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file functionObjectTemplate.C
Making dependency list for source file FilterFunctionObjectTemplate.C
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh: In member function ‘virtual void Foam::FunctionObject::write()’:
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:20:42: warning: array subscript is above array bounds [-Warray-bounds]
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:20:19: warning: array subscript is above array bounds [-Warray-bounds]
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:20:19: warning: array subscript is above array bounds [-Warray-bounds]
'/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/dynamicCode/_a43832a4c92be3f67897563bacc2c678008661f2/../platforms/linux64GccDPOpt/lib/lib_a43832a4c92be3f67897563bacc2c678008661f2.so' is up to date.
Time = 0
...
but the code seems to run fine. In turn, when I try to export that variable (into the namespace polarMeshVariables):

Code:
Starting time loop

Reading/calculating field UMean

fieldAverage: starting averaging at time 0

swak4Foam: Setting default mesh
swak4Foam: Allocating new repository for sampledGlobalVariables
Using dynamicCode for functionObject polarMesh at line 339 in "/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh"
Creating new library in "dynamicCode/_9dbdf78941043e646b703baa5235446b127c8dcb/platforms/linux64GccDPOpt/lib/lib_9dbdf78941043e646b703baa5235446b127c8dcb.so"
Invoking "wmake -s libso /home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/dynamicCode/_9dbdf78941043e646b703baa5235446b127c8dcb"
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file functionObjectTemplate.C
Making dependency list for source file FilterFunctionObjectTemplate.C
In file included from /home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/bool.H:58:0,
                 from /home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/UList.H:45,
                 from /home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/List.H:43,
                 from /home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/stringList.H:42,
                 from functionObjectTemplate.H:36,
                 from functionObjectTemplate.C:26:
/home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/pTraits.H: In instantiation of ‘Foam::pTraits<double [1]>’:
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:32:117:   instantiated from here
/home/holivares/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/pTraits.H:51:7: error: base type ‘double [1]’ fails to be a struct or class type
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh: In member function ‘virtual void Foam::FunctionObject::write()’:
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:32:117: error: no matching function for call to ‘Foam::ExpressionResult::ExpressionResult(Foam::scalar [1])’
/home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh:32:117: note: candidates are:
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:110:5: note: template<class Type> Foam::ExpressionResult::ExpressionResult(const Type&, typename Foam::ExpressionResult::enable_if_rank0<Foam::pTraits<T>::rank>::type*)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:100:5: note: template<class Type> Foam::ExpressionResult::ExpressionResult(const Foam::dimensioned<Type>&)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:96:5: note: template<class Type> Foam::ExpressionResult::ExpressionResult(const Foam::Field<Type>&)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:92:5: note: Foam::ExpressionResult::ExpressionResult(const Foam::dictionary&, bool)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:92:5: note:   no known conversion for argument 1 from ‘Foam::scalar [1] {aka double [1]}’ to ‘const Foam::dictionary&’
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:89:5: note: Foam::ExpressionResult::ExpressionResult(const Foam::ExpressionResult&)
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:89:5: note:   no known conversion for argument 1 from ‘Foam::scalar [1] {aka double [1]}’ to ‘const Foam::ExpressionResult&’
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:86:5: note: Foam::ExpressionResult::ExpressionResult()
/home/holivares/OpenFOAM/holivares-2.1.x/myapplications/swak4Foam/Libraries/swak4FoamParsers/lnInclude/ExpressionResult.H:86:5: note:   candidate expects 0 arguments, 1 provided
make: *** [Make/linux64GccDPOpt/functionObjectTemplate.o] Error 1


--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/_9dbdf78941043e646b703baa5235446b127c8dcb/platforms/linux64GccDPOpt/lib/lib_9dbdf78941043e646b703baa5235446b127c8dcb.so"


file: /home/holivares/OpenFOAM/holivares-2.1.x/run/swakSources/cylinderfive/system/controlDict::functions::polarMesh from line 339 to line 0.

    From function codedBase::createLibrary(..)
    in file db/dynamicLibrary/codedBase/codedBase.C at line 202.

FOAM exiting
although I have to admit that I might have ill-defined something in the C++ code (although I tried different definitions of the array and none seem to worked) .

What am I doing wrong?

Thank you very much,

h
I'm afraid the pythonIntegration currently only allows uniform scalars and vectors (and numpy-arrays is .... brave). Nevertheless: a segmentation fault is an unacceptable reaction. Could I please have a bug-report?

About the coded solution: I think the problem is that you use a C-array. The two things that can be moved to swak are either single values or Fields (in your case: scalar or scalarField)
gschaider is offline   Reply With Quote

Old   August 8, 2012, 12:27
Default
  #12
New Member
 
Hugo
Join Date: Jan 2011
Location: Montreal
Posts: 27
Rep Power: 15
Hugoles is on a distinguished road
I see, I was moving in the wrong direction, thank you for the feedback! I will fill a bug report as soon as possible.

But if I may, in line with my stubbornness: I need the arrays to define the coordinates of points (a polar mesh) at which location I need to calculate the velocity. That velocity, in turn, is needed to perform other operations and calculate some variables (a force) that in the end should be interpolated onto the cartesian mesh.

If I tried to sample the values of the velocity at the given locations (using probes), how could I ask swak to make calculations using only the sampled velocities? And if that is possible, how could I take the desired quantity back to the original cells?

thanks again for all your help (sorry for insisting so much on this!),

h
Hugoles is offline   Reply With Quote

Old   August 20, 2012, 16:44
Default
  #13
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hugoles View Post
I see, I was moving in the wrong direction, thank you for the feedback! I will fill a bug report as soon as possible.

But if I may, in line with my stubbornness: I need the arrays to define the coordinates of points (a polar mesh) at which location I need to calculate the velocity. That velocity, in turn, is needed to perform other operations and calculate some variables (a force) that in the end should be interpolated onto the cartesian mesh.

If I tried to sample the values of the velocity at the given locations (using probes), how could I ask swak to make calculations using only the sampled velocities? And if that is possible, how could I take the desired quantity back to the original cells?

thanks again for all your help (sorry for insisting so much on this!),

h
Calculations on probe locations can be done via "sampledSet" in swak4Foam. Problem is that for the locations of the probes you'll have to rely on the specifications of sets in OpenFOAM and I don't know whether there is one for that polar-mesh. But you could always use the "cloud"-set (I think that's the name)

Getting the sampledSet-values back to the cells is currently not supported. I'm currently working on something (Plugin-functions) that would allow this
gschaider is offline   Reply With Quote

Old   October 4, 2013, 06:19
Default
  #14
Member
 
alighaffari
Join Date: May 2011
Posts: 31
Rep Power: 14
alighaffari is on a distinguished road
Hi Hugoles
I want to add a source term in the momentum equation of the "interFoam" solver. It seems that "swak4Foam" has solved this problem with "InterFoamWithSources".
http://openfoamwiki.net/index.php/Co...oamWithSources

But I could not find any document and/or example to show me how to use it. It is obvious that a "momentumSourceDict" file should be created in "constant" folder. I have no Idea on the structure of this file. If you could provide me any insight it will be most appreciated.
alighaffari is offline   Reply With Quote

Old   October 4, 2013, 07:26
Default
  #15
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by alighaffari View Post
Hi Hugoles
I want to add a source term in the momentum equation of the "interFoam" solver. It seems that "swak4Foam" has solved this problem with "InterFoamWithSources".
http://openfoamwiki.net/index.php/Co...oamWithSources

But I could not find any document and/or example to show me how to use it. It is obvious that a "momentumSourceDict" file should be created in "constant" folder. I have no Idea on the structure of this file. If you could provide me any insight it will be most appreciated.
There comes an example case with that solver. The dict should be in that
__________________
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
gschaider is offline   Reply With Quote

Old   October 4, 2013, 10:08
Default
  #16
New Member
 
Hugo
Join Date: Jan 2011
Location: Montreal
Posts: 27
Rep Power: 15
Hugoles is on a distinguished road
Hello Alighaffari,

Like Bernhard suggests, best thing would be to follow the example of interFoam. I post an example of the structure of momentumSourceDict in case it makes things easier:

Code:
UEqn {
   variables (
   "cellLengthX=0.004;"
   "force=-5375;
   "nada=vector(0,0,0);" 
             );
  expression  "pos().x<=cellLengthX ? vector(force,0,0) : nada";

   lookuptables (
                );

   dimensions [0 1 -2 0 0 0 0];

storedVariables (
    {
    }

);

}
you just have the header above this in case it complains, although I think you won't need it.

Hope it helps,

Hugo
Hugoles is offline   Reply With Quote

Old   October 5, 2013, 10:17
Default
  #17
Member
 
alighaffari
Join Date: May 2011
Posts: 31
Rep Power: 14
alighaffari is on a distinguished road
Hello Hugo and Bernhard
thanks for your reply. it was very helpful.
alighaffari is offline   Reply With Quote

Old   October 6, 2013, 11:45
Default source term from solution of a PDE
  #18
Member
 
alighaffari
Join Date: May 2011
Posts: 31
Rep Power: 14
alighaffari is on a distinguished road
Hello guys again
In my case study the source term at each time step should be obtained from the solution of a Partial differential equation (Maxwell equation in magneto-static). Is it possible to define the PDE in "momentumSourceDict"? or is there any other way to handle this problem? What is your idea? Any help would be greatly appreciated.
Regards
Ali
alighaffari is offline   Reply With Quote

Old   October 6, 2013, 18:29
Default
  #19
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by alighaffari View Post
Hello guys again
In my case study the source term at each time step should be obtained from the solution of a Partial differential equation (Maxwell equation in magneto-static). Is it possible to define the PDE in "momentumSourceDict"? or is there any other way to handle this problem? What is your idea? Any help would be greatly appreciated.
Regards
Ali
No you can't specify a PDE there. There are two functionObjects that solve a PDE in swak: one for a transport equation the other for a laplacian equation. The solution field of those can be used in any other swak-expression
__________________
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
gschaider is offline   Reply With Quote

Old   October 10, 2013, 11:09
Default
  #20
Member
 
alighaffari
Join Date: May 2011
Posts: 31
Rep Power: 14
alighaffari is on a distinguished road
Hello Bernhard
Do you have any tutorial or example that teach me how to define a source term from solving a PDE and how to apply it to interFoam solver. If could kindly send me any example related to this field it will be very helpful for me.
Regards
Ali Ghaffari
alighaffari is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
InterDyMFoam+simpleFunctionObject Elham OpenFOAM Running, Solving & CFD 5 July 10, 2017 11:59
[swak4Foam] and twoPhaseEulerFoam mnikku OpenFOAM Community Contributions 1 February 19, 2016 05:21
source term in near wall cell rajcfd OpenFOAM Pre-Processing 5 February 1, 2016 10:31
[swak4Foam] Install swak4Foam on OpenFOAM1.7.1 on Ubuntu 13.04 kobayashi OpenFOAM Community Contributions 2 January 5, 2014 17:33
[swak4Foam] fails in parallel with -otherTime? Phicau OpenFOAM Community Contributions 3 June 26, 2013 13:00


All times are GMT -4. The time now is 04:25.