CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

nonUniform internalField using codeStream

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By clapointe

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 9, 2018, 10:43
Default nonUniform internalField using codeStream
  #1
Member
 
Saleh Abuhanieh
Join Date: Nov 2017
Posts: 83
Rep Power: 9
Saleh Abuhanieh is on a distinguished road
Hi Foamers,


I am trying to set the internalField for a scalar field phi according to a simple formula using sodeStream. The task shall be easy, I used for boundaryField successfully, however I am receiving error during running the case.


- in 0/rho file


internalField #codeStream
{
codeInclude
#{
#include "fvCFD.H"
#};

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
#};

codeLibs
#{
-lmeshTools \
-lfiniteVolume
#};

code
#{
const IOdictionary& d = static_cast<const IOdictionary&>
(
dict.parent().parent()
);

const fvMesh& mesh = refCast<const fvMesh>(d.db());

scalarField rho(mesh.nCells(), 0);
forAll(rho, i)
{
const scalar x = mesh.C()[i][0];
const scalar y = mesh.C()[i][1];
rho[i] = x*(y-1.0);

}
rho.writeEntry("", os);

#};
};




- the error





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

Create mesh for time = 0

Reading physicalProperties

Reading field phi

Reading field rho

Using #codeStream at line 19 in file "//Example_3_4/0/rho"
Using #codeStream with "//Example_3_4/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_fb6fa2a2647a8c56be151bdd6cfc899b6f3a 075e.so"
Creating new library in "dynamicCode/_fb6fa2a2647a8c56be151bdd6cfc899b6f3a075e/platforms/linux64GccDPInt32Opt/lib/libcodeStream_fb6fa2a2647a8c56be151bdd6cfc899b6f3a 075e.so"
Invoking "wmake -s libso ///Example_3_4/dynamicCode/_fb6fa2a2647a8c56be151bdd6cfc899b6f3a075e"
wmake libso ///Example_3_4/dynamicCode/_fb6fa2a2647a8c56be151bdd6cfc899b6f3a075e
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: ///Example_3_4/dynamicCode/_fb6fa2a2647a8c56be151bdd6cfc899b6f3a075e/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_fb6fa2a2647a8c56be151bdd6cfc899b6f3a 075e.so
#0 Foam::error:rintStack(Foam::Ostream&) at ??:?
#1 Foam::sigSegv::sigHandler(int) at ??:?
#2 ? in "/lib/x86_64-linux-gnu/libc.so.6"
#3 __dynamic_cast in "/usr/lib/x86_64-linux-gnu/libstdc++.so.6"
#4 codeStream_fb6fa2a2647a8c56be151bdd6cfc899b6f3a075 e at /opt/openfoam5/src/OpenFOAM/lnInclude/typeInfo.H:110
#5 Foam::functionEntries::codeStream::execute(Foam::d ictionary const&, Foam:rimitiveEntry&, Foam::Istream&) at ??:?
#6 Foam::functionEntry::execute(Foam::word const&, Foam::dictionary const&, Foam:rimitiveEntry&, Foam::Istream&) at ??:?
#7 Foam:rimitiveEntry::expandFunction(Foam::word const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#8 Foam:rimitiveEntry::append(Foam::token const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#9 Foam:rimitiveEntry::read(Foam::dictionary const&, Foam::Istream&) at ??:?
#10 Foam:rimitiveEntry::readEntry(Foam::dictionary const&, Foam::Istream&) at ??:?
#11 Foam:rimitiveEntry:rimitiveEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#12 Foam::entry::New(Foam::dictionary&, Foam::Istream&) at ??:?
#13 Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#14 Foam:perator>>(Foam::Istream&, Foam::dictionary&) at ??:?
#15 Foam::baseIOdictionary::readData(Foam::Istream&) at ??:?
#16 Foam::fileOperations::uncollatedFileOperation::rea d(Foam::regIOobject&, bool, Foam::IOstream::streamFormat, Foam::word const&) const at ??:?
#17 Foam::regIOobject::readHeaderOk(Foam::IOstream::st reamFormat, Foam::word const&) at ??:?
#18 Foam::localIOdictionary::localIOdictionary(Foam::I Oobject const&, Foam::word const&) at ??:?
#19 Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::readFields() in "//Example_3_4"
#20 Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject const&, Foam::fvMesh const&) in "///Example_3_4"
#21 ? in "/OpenFOAM/-5.0/platforms/linux64GccDPInt32Opt/bin/Example_3_4"
#22 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#23 ? in "/OpenFOAM/-5.0/platforms/linux64GccDPInt32Opt/bin/Example_3_4"
Segmentation fault (core dumped)




when I set any uniform value .. the solver works


I hope the case is clear


Any help will be appreciated
Saleh Abuhanieh is offline   Reply With Quote

Old   July 12, 2018, 04:14
Default
  #2
Member
 
Saleh Abuhanieh
Join Date: Nov 2017
Posts: 83
Rep Power: 9
Saleh Abuhanieh is on a distinguished road
any support pls?
Saleh Abuhanieh is offline   Reply With Quote

Old   July 16, 2018, 16:04
Default
  #3
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
Check out this tutorial : https://wiki.openfoam.com/Programming2.

Caelan
clapointe is offline   Reply With Quote

Old   July 17, 2018, 10:15
Default
  #4
Member
 
Saleh Abuhanieh
Join Date: Nov 2017
Posts: 83
Rep Power: 9
Saleh Abuhanieh is on a distinguished road
Thank you ..
it is ok now
Saleh Abuhanieh is offline   Reply With Quote

Old   July 25, 2018, 12:43
Default
  #5
New Member
 
chen qi
Join Date: Apr 2018
Posts: 2
Rep Power: 0
chenqi is on a distinguished road
Hi, I have the same error, Can you tell me how to solve the problem. Thank you in advance.
chenqi is offline   Reply With Quote

Old   July 25, 2018, 16:09
Default
  #6
Member
 
Saleh Abuhanieh
Join Date: Nov 2017
Posts: 83
Rep Power: 9
Saleh Abuhanieh is on a distinguished road
Hi,

Check the first two lines in the code part (which gives the access for internal mesh information). this part is different in case of BC
Saleh Abuhanieh is offline   Reply With Quote

Old   March 4, 2020, 11:19
Default
  #7
New Member
 
Guangyu
Join Date: Mar 2020
Posts: 7
Rep Power: 6
Guangyu is on a distinguished road
Quote:
Originally Posted by clapointe View Post
Check out this tutorial : https://wiki.openfoam.com/Programming2.

Caelan
Hi, Caelan,

Many thanks for your post. I've checked out the tutorial and met similar problems with Saleh.

The 0/U file and the error message are as follows:

*********************************************
velocity-inlet-5
{
type fixedValue;
value #codeStream
{
codeInclude
#{
#include "fvCFD.H"
#};

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
#};

//libs needed to visualize BC in paraview
codeLibs
#{
-lmeshTools \
-lfiniteVolume
#};

code
#{
const IOdictionary& d = static_cast<const IOdictionary&>
(
dict.parent().parent()
);

const fvMesh& mesh = refCast<const fvMesh>(d.db());
const label id = mesh.boundary().findPatchID("velocity-inlet-5");
const fvPatch& patch = mesh.boundary()[id];

//vectorField U(mesh.boundary()[id].size(), vector(0, 0, 0));
vectorField U(patch.size(), vector(0, 0, 0));

const scalar pi = constant::mathematical::pi;
const scalar U_0 = 2.; //max vel
const scalar p_ctr = 8.; //patch center
const scalar p_r = 8.; //patch radius

forAll(U, i)
{
const scalar y = patch.Cf()[i][1];
U[i] = vector(U_0*(1-(pow(y - p_ctr,2))/(p_r*p_r)), 0., 0.);
}

//for (int i; i<patch.size() ; i++)
//{
// const scalar y = patch.Cf()[i][1];
// U[i] = vector(U_0*(1-(pow(y - p_ctr,2))/(p_r*p_r)), 0., 0.);
//}

writeEntry(os, "", U);
#};
};
}

************************************************** *

The error message:

Create time

Create mesh for time = 0

Reading transportProperties

Reading field p

Reading field U

Using #codeStream at line 32 in file "/users/szb15180/lustre/OpenFOAM/Day11_programming_1/Implementing_BC_using_codeStream/2Delbow_UparabolicInlet/0/U.boundaryField.velocity-inlet-5"
Using #codeStream with "/users/szb15180/lustre/OpenFOAM/Day11_programming_1/Implementing_BC_using_codeStream/2Delbow_UparabolicInlet/dynamicCode/platforms/linux64IccDPInt32Opt/lib/libcodeStream_6f24639605d8ca85b20529455e75474847b7 09e7.so"
Creating new library in "dynamicCode/_6f24639605d8ca85b20529455e75474847b709e7/platforms/linux64IccDPInt32Opt/lib/libcodeStream_6f24639605d8ca85b20529455e75474847b7 09e7.so"
Invoking "wmake -s libso /users/szb15180/lustre/OpenFOAM/Day11_programming_1/Implementing_BC_using_codeStream/2Delbow_UparabolicInlet/dynamicCode/_6f24639605d8ca85b20529455e75474847b709e7"
wmake libso /users/szb15180/lustre/OpenFOAM/Day11_programming_1/Implementing_BC_using_codeStream/2Delbow_UparabolicInlet/dynamicCode/_6f24639605d8ca85b20529455e75474847b709e7
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /users/szb15180/lustre/OpenFOAM/Day11_programming_1/Implementing_BC_using_codeStream/2Delbow_UparabolicInlet/dynamicCode/_6f24639605d8ca85b20529455e75474847b709e7/../platforms/linux64IccDPInt32Opt/lib/libcodeStream_6f24639605d8ca85b20529455e75474847b7 09e7.so
#0 Foam::error::printStack(Foam::Ostream&) at ??:?
#1 Foam::sigSegv::sigHandler(int) at ??:?
#2 ? in "/usr/lib64/libc.so.6"
#3 codeStream_6f24639605d8ca85b20529455e75474847b709e 7 at /opt/software/openfoam/intel-2018.2/v7/src/OpenFOAM/lnInclude/dictionary.H:285
#4 Foam::functionEntries::codeStream::execute(Foam::d ictionary const&, Foam::primitiveEntry&, Foam::Istream&) at ??:?
#5 Foam::functionEntry::execute(Foam::word const&, Foam::dictionary const&, Foam::primitiveEntry&, Foam::Istream&) at ??:?
#6 Foam::primitiveEntry::expandFunction(Foam::word const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#7 Foam::primitiveEntry::append(Foam::token const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#8 Foam::primitiveEntry::read(Foam::dictionary const&, Foam::Istream&) at ??:?
#9 Foam::primitiveEntry::readEntry(Foam::dictionary const&, Foam::Istream&) at ??:?
#10 Foam::primitiveEntry::primitiveEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#11 Foam::entry::New(Foam::dictionary&, Foam::Istream&) at ??:?
#12 Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#13 Foam::dictionary::dictionary(Foam::fileName const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#14 Foam::dictionaryEntry::dictionaryEntry(Foam::keyTy pe const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#15 Foam::entry::New(Foam::dictionary&, Foam::Istream&) at ??:?
#16 Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#17 Foam::dictionary::dictionary(Foam::fileName const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#18 Foam::dictionaryEntry::dictionaryEntry(Foam::keyTy pe const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#19 Foam::entry::New(Foam::dictionary&, Foam::Istream&) at ??:?
#20 Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#21 Foam::operator>>(Foam::Istream&, Foam::dictionary&) at ??:?
#22 Foam::baseIOdictionary::readData(Foam::Istream&) at ??:?
#23 Foam::fileOperations::uncollatedFileOperation::rea d(Foam::regIOobject&, bool, Foam::IOstream::streamFormat, Foam::word const&) const at ??:?
#24 Foam::regIOobject::readHeaderOk(Foam::IOstream::st reamFormat, Foam::word const&) at ??:?
#25 Foam::localIOdictionary::localIOdictionary(Foam::I Oobject const&, Foam::word const&) at ??:?
#26 Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject const&, Foam::fvMesh const&) at ??:?
#27 ? at ??:?
#28 __libc_start_main in "/usr/lib64/libc.so.6"
#29 ? at ??:?
Segmentation fault

************************************

Do you have any idea what went wrong?

Your kind help is very much appreciated.

Best wishes;

Guangyu
Guangyu is offline   Reply With Quote

Old   March 4, 2020, 12:21
Default
  #8
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
I am not sure how you came about this code, but the initialization does not match that from the tutorial (or any of the others that I've seen via a quick google). A quick look at your error makes me suspect the creation of the dict as at least one problem.

Caelan
clapointe is offline   Reply With Quote

Old   March 4, 2020, 12:31
Default
  #9
New Member
 
Guangyu
Join Date: Mar 2020
Posts: 7
Rep Power: 6
Guangyu is on a distinguished road
Quote:
Originally Posted by clapointe View Post
I am not sure how you came about this code, but the initialization does not match that from the tutorial (or any of the others that I've seen via a quick google). A quick look at your error makes me suspect the creation of the dict as at least one problem.

Caelan
Hi, Caelan,

Thank you so much for relying. The tutorial from your link is Programming2. The case I'm work with is Programming1, from the same place, three-week tutorial series, day 11, "Programming - Implementing boundary condtions using codeStream".

I'll trying your case (Programming2, initialization case) to see what happens.

Thanks again.
Guangyu is offline   Reply With Quote

Old   September 17, 2021, 08:48
Default
  #10
New Member
 
Join Date: Feb 2016
Posts: 13
Rep Power: 10
fanny is on a distinguished road
Hi Guangy,
try to replace :


const IOdictionary& d = static_cast<const IOdictionary&>
(
dict.parent().parent()
);


with



const IOdictionary& d = static_cast<const IOdictionary&>(dict);




Best wishes
Fanny
fanny is offline   Reply With Quote

Reply


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
internalField condition mchehab2 OpenFOAM Running, Solving & CFD 14 November 10, 2022 14:28
[OpenFOAM] How to correctly show the result of #codeStream# internalField? chengdi ParaView 24 July 14, 2022 05:26
internalField nonuniform List<vector> and internalField nonuniform List <scalar> Ferdinand OpenFOAM Pre-Processing 1 January 3, 2020 13:20
internalField nonuniform <List>; Panagioto OpenFOAM Pre-Processing 14 September 2, 2019 12:51
How to create the internalField with #codeStream chun OpenFOAM Running, Solving & CFD 3 May 6, 2017 11:35


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