CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Specifying nonuniform boundary condition (https://www.cfd-online.com/Forums/openfoam-solving/57782-specifying-nonuniform-boundary-condition.html)

bigbang August 5, 2011 14:28

Hi. I don't know if it's because I'm using openFoam 2.0.0, but I get this error after trying to run the code

Code:

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#0  Foam::error::printStack(Foam::Ostream&) in "/opt/openfoam200/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1  Foam::sigSegv::sigHandler(int) in "/opt/openfoam200/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2  in "/lib/libc.so.6"
#3  std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) in "/usr/lib/libstdc++.so.6"
#4 
 in "/home/alexander/OpenFOAM/alexander-2.0.0/platforms/linux64GccDPOpt/bin/inletBC"
#5  __libc_start_main in "/lib/libc.so.6"
#6 
 in "/home/alexander/OpenFOAM/alexander-2.0.0/platforms/linux64GccDPOpt/bin/inletBC"
Segmentation fault

Any ideas? Basically when I don't put a patch name, the program says I'm missing an argument. When I do put a patch name it returns the error quoted above. Help. Thanks.

gschaider August 8, 2011 05:32

Quote:

Originally Posted by bigbang (Post 319071)
Hi. I don't know if it's because I'm using openFoam 2.0.0, but I get this error after trying to run the code

Code:

#2  in "/lib/libc.so.6"
#3  std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) in "/usr/lib/libstdc++.so.6"

Any ideas? Basically when I don't put a patch name, the program says I'm missing an argument. When I do put a patch name it returns the error quoted above. Help. Thanks.

Not 100% sure but usually if the code SegFaults at this basic_string the problem is that you're mixing binaries (library and exe) produced by two different g++-versions. But your milage may vary

bigbang August 8, 2011 07:33

Quote:

Originally Posted by gschaider (Post 319269)
Not 100% sure but usually if the code SegFaults at this basic_string the problem is that you're mixing binaries (library and exe) produced by two different g++-versions. But your milage may vary

Thanks for the reply gschaider. I don't think I understand where to go from here. Can you take a look at my code and wmake output.

Code:

Code:

#include "fvCFD.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

argList::validArgs.append("patchName");

#  include "setRootCase.H"

word patchName(args.args()[3]);

#  include "createTime.H"
#  include "createMesh.H"
#  include "createFields.H"
#  include "initContinuityErrs.H"

Info<< "This utility initializes gamma values for boundary patches based on" <<endl;
Info<< "a geometric limit. Default is set to: z>=0 ==>gamma=0, z<o ==>gamma=1." <<endl;
Info<< "These settings are presently only changeable by modifying the source code." <<endl;
Info<< "Source code to be found in: OF/user/applications." <<endl;
Info<< "Change code (.C file) according your needs and in that directory run wmake." <<endl;
Info<< "\nStarting time loop\n" << endl;

// Get index of patch
label inletPatchID = mesh.boundaryMesh().findPatchID(patchName);

// Get reference to boundary value
const fvPatchVectorField& centre = mesh.C().boundaryField()[inletPatchID];

//Uncomment the line for your case: U for velocity cases, gamma for gamma cases
fvPatchVectorField& Inlet = U.boundaryField()[inletPatchID];
//fvPatchScalarField& targetPatch = gamma.boundaryField()[inletPatchID];

// loop over all hub faces
forAll(Inlet, faceI)
{
// get coordinate for face centre
const vector& c = centre[faceI];

// c[0] is X coordinate, c[1] is Y coordinate, c[2] is Z coordinate
// Apply boundary condition based in one coordinate (X, Y, or Z).

if (c[2] < 0.3)
//if true: below watersurface
{
//targetPatch[faceI] =  scalar (1);
Inlet[faceI] = vector (1, 0, 0);
}
//if false: at or above watersurface
else
{
//targetPatch[faceI] = scalar (0);
Inlet[faceI] = vector (10 ,0 ,0);
}

}

// Force the write
//gamma.write();
U.write();

Info<< "\n ExecutionTime = "
<< runTime.elapsedCpuTime()
<< " s\n" << endl;

Info<< "End" << endl;

return(0);
}

wmake output:

Code:

Making dependency list for source file inletBC.C
SOURCE=inletBC.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam200/src/finiteVolume/lnInclude -I/opt/openfoam200/src/meshTools/lnInclude -IlnInclude -I. -I/opt/openfoam200/src/OpenFOAM/lnInclude -I/opt/openfoam200/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/inletBC.o
/opt/openfoam200/src/finiteVolume/lnInclude/initContinuityErrs.H: In function ‘int main(int, char**)’:
/opt/openfoam200/src/finiteVolume/lnInclude/initContinuityErrs.H:37: warning: unused variable ‘cumulativeContErr’
g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam200/src/finiteVolume/lnInclude -I/opt/openfoam200/src/meshTools/lnInclude -IlnInclude -I. -I/opt/openfoam200/src/OpenFOAM/lnInclude -I/opt/openfoam200/src/OSspecific/POSIX/lnInclude  -fPIC -Xlinker --add-needed Make/linux64GccDPOpt/inletBC.o -L/opt/openfoam200/platforms/linux64GccDPOpt/lib \
            -lfiniteVolume -lmeshTools -lOpenFOAM -ldl  -lm -o /home/alexander/OpenFOAM/alexander-2.0.0/platforms/linux64GccDPOpt/bin/inletBC


gschaider August 8, 2011 09:44

Quote:

Originally Posted by bigbang (Post 319295)
Thanks for the reply gschaider. I don't think I understand where to go from here. Can you take a look at my code and wmake output.

If my theory is correct then NO utilitiy you compiled yourself should work. The reason would be that the compiler that was used for compiling OF used another library for the strings (probably because it was another version of the compiler) than the compiler you're using now. Check this by compiling another 3rd party utility. Or by copying the sources of a utility that comes with OF, modifying the Make/files (so that you don't overwrite the original binary), compiling and runnig that.

If I'm wrong then I can't help you. If I'm right you'll either have to recompile OF or find out which compiler was actually used for your distro

Good luck

bigbang August 8, 2011 09:56

Quote:

Originally Posted by gschaider (Post 319326)
Check this by compiling another 3rd party utility. Or by copying the sources of a utility that comes with OF, modifying the Make/files (so that you don't overwrite the original binary), compiling and runnig that.

I copied the icoFoam source and added a scalar transport model for Temperature following an online tutorial and it ran perfectly. I will pursue a new direction thanks.

gschaider August 8, 2011 10:39

Quote:

Originally Posted by bigbang (Post 319329)
I copied the icoFoam source and added a scalar transport model for Temperature following an online tutorial and it ran perfectly. I will pursue a new direction thanks.

Aaaa. It was so obvious:

word patchName(args.args()[3]);

that is pre 1.5-convention. Use 0 instead of 3.

bigbang August 8, 2011 11:38

Ahh. Thank you. I fixed this since I am running OF 2.0.0. It worked, but then I get the same error further into the code...

Code:

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading field U

This utility initializes gamma values for boundary patches based on
a geometric limit. Default is set to: z>=0 ==>gamma=0, z<o ==>gamma=1.
These settings are presently only changeable by modifying the source code.
Source code to be found in: OF/user/applications.
Change code (.C file) according your needs and in that directory run wmake.

Starting time loop

#0  Foam::error::printStack(Foam::Ostream&) in "/opt/openfoam200/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1  Foam::sigSegv::sigHandler(int) in "/opt/openfoam200/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2  in "/lib/libc.so.6"
#3 
 in "/home/alexander/OpenFOAM/alexander-2.0.0/platforms/linux64GccDPOpt/bin/inletBC"
#4  __libc_start_main in "/lib/libc.so.6"
#5 
 in "/home/alexander/OpenFOAM/alexander-2.0.0/platforms/linux64GccDPOpt/bin/inletBC"
Segmentation fault
alexander@alexander-G50VT:~/OpenFOAM/alexander-2.0.0/run/testCase$

Is there another convention in there that may not be up to standard for OF 2.0.0?

gschaider August 8, 2011 14:08

Quote:

Originally Posted by bigbang (Post 319343)
Ahh. Thank you. I fixed this since I am running OF 2.0.0. It worked, but then I get the same error further into the code...

Code:

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading field U

This utility initializes gamma values for boundary patches based on
a geometric limit. Default is set to: z>=0 ==>gamma=0, z<o ==>gamma=1.
These settings are presently only changeable by modifying the source code.
Source code to be found in: OF/user/applications.
Change code (.C file) according your needs and in that directory run wmake.

Starting time loop

#0  Foam::error::printStack(Foam::Ostream&) in "/opt/openfoam200/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1  Foam::sigSegv::sigHandler(int) in "/opt/openfoam200/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2  in "/lib/libc.so.6"
#3 
 in "/home/alexander/OpenFOAM/alexander-2.0.0/platforms/linux64GccDPOpt/bin/inletBC"
#4  __libc_start_main in "/lib/libc.so.6"
#5 
 in "/home/alexander/OpenFOAM/alexander-2.0.0/platforms/linux64GccDPOpt/bin/inletBC"
Segmentation fault
alexander@alexander-G50VT:~/OpenFOAM/alexander-2.0.0/run/testCase$

Is there another convention in there that may not be up to standard for OF 2.0.0?

No idea. SegFault is usually accessing an element that is not in a list. Do yourself a favour and compile yourself a Debug-version of OF if you want to go into developing. The Debug-version checks for such array out of bounds errors and aborts with meaningful error messages (but this comes at the expense of performance).

If that is too much action for you sprinkle the code with "Info << "-statements and see how far it gets (my personal guess is that you specified a nno-existing patch, because the code never checks whether the patch is really there)

bigbang August 8, 2011 14:26

Thank you for the Info<< sprinkler idea. I did it and realized that my loop wasn't accepting the parameters in forAll(). Looking further into the problem I noticed that the patchID was -1 for all patches meaning it wasn't retrieving the patch correctly. I just fed the program the value 4 for my inlet and it works fine now.

Thanks again!

Taylor November 5, 2012 05:56

Quote:

Originally Posted by markc (Post 192874)


hi Markc
I am a new hand in OpenFoam, in my case I want to set the blasius profile at inlet, but I have no ideal about these. I try to use your file in my case, but it doesn´t work, because the youdidn´t set the type name of the new boundary, if I use setboundarygamma in 0file, It couldn´t be recognize.
please forgive me if my question is stupid.
Thanks in advance.


now I know it, thank you very much. I mix the solver and the new boundary condition. thank you very much.


Taylor

Taylor November 5, 2012 06:01

hi,

I am sorry if I disturb you. do you solve the blasuis boundary condition in OpenFoam?
now I am crazy for this problem.

Taylor

Quote:

Originally Posted by ami (Post 192862)
Hi Chen Jun

I am interested in considering nonuniform boundary conditions in my computations (e.g., a laminar Blasius boundary layer inflow condition along the free stream flow condition). Please can you specify the file name you described and how to use it?

thanks


Taylor November 6, 2012 07:47

Quote:

Originally Posted by hani (Post 192863)
This thread actually belongs in preprocessing. Anyway, Chen actually describes the basics of how to set your boundary conditions. It is however a bit difficult to understand for a beginner. Let me, as a slightly more than beginner try to help you in a more detailed way (there might be other solutions also):

It is unlikely that there is such a boundary condition already implemented and distributed in OpenFoam. You will have to implement it yourself. This goes at least for less common bc's.

A suggestion on how to implement the steady bc (reads 0 and overwrites 0):

Step 1:
Copy the source directory of the particular solver that you want to use to your personal applications directory. For instance:
mkdir ~/OpenFOAM/hani-1.2/applications (if you don't have it)
cp -r OpenFOAM/OpenFOAM-1.2/applications/solvers/incompressible/simpleFoam ~/OpenFOAM/hani-1.2/applications/

Step 2:
Rename your copied directory to something that makes sence, for instance:
mv ~/OpenFOAM/hani-1.2/applications/simpleFoam ~/OpenFOAM/hani-1.2/applications/blasiusBC
Rename the .C-file in your blasiusBC directory to blasiusBC.C
Edit blasiusBC.C: Insert correct descriptions for Application and Description in the header of the file, for clarity. Remove everything in the main function except the include statements in the beginning. You may later on check which ones you actually need by commenting them and try to compile. The compiler error messages will guide you.

Step 3:
Implement your bc's using the directives that Chen gave you. This should be located after the include statements in the main function.
Write out the variables you have changed at the end of the main function:
// Force the write
U.write();
k.write();
epsilon.write();
phi.write();

Info<< "\n ExecutionTime = "
<< runTime.elapsedCpuTime()
<< " s\n" << endl;

Info<< "End" << endl;

return(0);

Step 4:
Edit blasiusBC/Make/files to make sure that the filenames blasiusBC is used instead of the name of the original application.

Step 5:
Compile.
Move to your blasiusBC directory and type
wmake

Step 6:
type:
rehash
to make the executable available.

Step 7:
Set your bc's by typing:
blasiusBC <root> <case>
which will change the files in your <root>/<case>/0 directory to include the bc's you defined in blasiusBC.

Step 8:
Run your case using the solver you need for the application. It will read the 0 directory and get the correct bc's.

Good luck!
Håkan.


thank you very much, I use it and works fine, really thank you

isabel September 13, 2013 12:20

Dear everybody,

In this forum you explain how to implement a non-uniform value as boundary condition. For instance, U=whatever.
I need to implement a non uniform temperature gradient as boundary condition. How can I do it?

Regards

gschaider September 16, 2013 15:20

Quote:

Originally Posted by isabel (Post 451582)
Dear everybody,

In this forum you explain how to implement a non-uniform value as boundary condition. For instance, U=whatever.
I need to implement a non uniform temperature gradient as boundary condition. How can I do it?

Regards

From me you're going to hear "groovyBC". Others will tell you "coded". Second is with C++-programming, first without

zcarral September 19, 2013 05:45

Dear Bernard,

I agree that "groovyBC" is an option but perhaps there is a way to program a non uniform temperature gradient. Does anybody know how to program it?

isabel February 12, 2014 06:04

Dear everybody,

I am using groovyBC to set the boundary condition gradT=2*x
I have written this code:

top
{
type groovyBC;
gradientExpression "gradT";
fractionExpression "0";
variables "gradT=2*mesh.C().component(vector::X);";
timelines ( );
}


And I have the following error:

--> FOAM FATAL ERROR:
Parser Error at "1.3-6" :"field mesh not existing or of wrong type"
"2*mesh.C().component(vector::X)"
" ^^^^ "

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

FOAM exiting

How can I call x coordinate using groovyBC?

isabel February 13, 2014 07:08

Problem solved. This is the correct code:

top
{
type groovyBC;
gradientExpression "gradT";
fractionExpression "0";
variables "gradT=2*pos().x;";
timelines ( );
}

gironidegirona October 21, 2014 13:28

Boundary on the variable boundaryField
 
Hi you all,

I think that your proposal solution for a variable boundary condition (I understand in time) is to modify the solver.

I would like to have a variable boundary condition depending on the position on the boundary itself. My approach is to modify the (for example) U values list and on the boundary set the value of each element on a list. The thing to know is if this is possible, and if it is how I do that? which is the element order?
example:

Inlet
{
list of values on each boundary element
}


Thanks in advance

wc34071209 October 21, 2014 14:37

i dont think doing this way is a wise idea, it is doable though.

gschaider October 22, 2014 14:52

Quote:

Originally Posted by gironidegirona (Post 515397)
Hi you all,

I think that your proposal solution for a variable boundary condition (I understand in time) is to modify the solver.

I would like to have a variable boundary condition depending on the position on the boundary itself. My approach is to modify the (for example) U values list and on the boundary set the value of each element on a list. The thing to know is if this is possible, and if it is how I do that? which is the element order?
example:

Inlet
{
list of values on each boundary element
}


Thanks in advance

No. Boundary condition should never go into the solver. Only Fortran-Programmers do such a thing.

Possible solutions are the coded-BoundaryCondition that comes with OpenFOAM (there you've got to program in C++) or the groovyBC that comes with swak4Foam (a bit easier to use I like to think)


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