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/)
-   -   TimeVaryingMappedFixedValue field creation (https://www.cfd-online.com/Forums/openfoam-solving/58251-timevaryingmappedfixedvalue-field-creation.html)

johndeas January 9, 2008 15:21

Hi, I would like to output
 
Hi,

I would like to output fields that will serve as inputs for a timeVaryingMappedFixedValue patch. I will have to write all the files in the constant/boundaryData/inlet folder (points and speed) using the field of cyclic patch. I would have liked to know if someone already did this (and can give some direction on how to retrieve fields at boundaries), and if the numbering will be consistent between all files (i.e. are the faces automatically crawled with the same order across the patch for all field and the position).

Thanks,

J.D.

mattijs January 10, 2008 04:53

Get patchfield of e.g. p goes
 
Get patchfield of e.g. p goes something like

label patchI = mesh.boundaryMesh().findPatchID("myCyclicPatch");

Info<< "patchField is " << p.boundaryField()[patchI] << endl;

The timeVaryingMappedFixedValue does a triangulation of the points and interpolation so ordering does not matter.

Search for boundaryField on this forum or the Wiki and you'll find more info.

johndeas January 10, 2008 05:28

It is not the order during rea
 
It is not the order during reading that worried me, but the order when writing the boundaryData files. I wanted to know if 14th value of U would always be assigned to the 14th point in "points" for example.

mattijs January 10, 2008 16:39

Yes. The interpolation factors
 
Yes. The interpolation factors (nearestVertex_, nearestVertexWeight_) are calculated once and then the interpolation always proceeds in the same order.

timeVaryingMappedFixedValueFvPatchField.C line 630.

johndeas January 14, 2008 05:44

Hi, I tried to use an IOobj
 
Hi,

I tried to use an IOobject to store the velocity field contained in one of my periodic boundary condition to create the field at each timestep, as future input fields for another calculation, which will use a timeVaryingMappedFixedValue patch as the rest of this thread suggests.

Based on the way the lambda2 field is written at each timestep in lambda2.c, I added the following code to my solver (a modification of icoFoam) :

word inletPatchName = "cyclic";

vectorField UBoundField
(
IOobject
(
"UBoundField",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
U.boundaryField()[patchID]
);

The compilation gave me the following error :

sandFoam.C:159: error: no matching function for call to 'Foam::Field<foam::vector<double> >::Field(Foam::IOobject, Foam::fvPatchField<foam::vector<double> >&)'
/home/vinz/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/Field.C:197: note: candidates are: Foam::Field<type>::Field(const Foam::word&, const Foam::dictionary&, Foam::label) [with Type = Foam::Vector<double>]
...
and a list of other constructors

I understand that I am not calling the vectorField constructor using the good types. U being of type volVectorField, U.boundaryField is of type "reference to GeometricBoundaryField". In the original IOobject in lambda2.c, one can read :

volScalarField Lambda2
(
IOobject
(
"Lambda2",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
-eigenValues(SSplusWW)().component(vector::Y)
);

A look at the Doxygen documentation teaches that: eigenValues() is of type dimensionedVector and as such -eigenValues(SSplusWW)().component(vector::Y) is of type dimensionedScalar.

My question is, how can I write the my IOobject for the velocity at the boundary to fill the IOobject with a dimensionedVector instead of U.boundaryField()[patchID] ? I hint that a local value as to be given (a vector or a scalar) which will be crawled on the domain specified to create a field (in the lambda2 example the domain would be 'mesh', which is of type FOAM::fvMesh). If this is the case, how can I create a domain (in the form of a mesh) that just contains my boundary condition, so as to call something which would look like

word inletPatchName = "cyclic";

vectorField UBoundField
(
IOobject
(
"UBoundField",
runTime.timeName(),
!!! boundarycondition domain !!!,
IOobject::NO_READ,
IOobject::NO_WRITE
),
!!! local value of U !!!
);

Thank you for you help,

J.D.

johndeas January 14, 2008 05:51

"I hint that a local value as
 
"I hint that a local value as to be given (a vector or a scalar) which will be crawled on the domain specified to create a field (in the lambda2 example the domain would be 'mesh', which is of type FOAM::fvMesh)."

This makes no sense... It is a field which is provided.

johndeas January 15, 2008 08:05

I looked into timeVaryingMappe
 
I looked into timeVaryingMappedFixedValueFvPatchField.C to understand how the patch reads its input fields to mimic its behaviour and be able to write those fields.

For the points, a pointIOField is created:

pointIOField samplePoints
(
IOobject
(
"points",
this->db().time().constant(),
"boundaryData"/this->patch().name(),
this->db(),
IOobject::MUST_READ,
IOobject::AUTO_WRITE,
false
)
);

There, this->db() refers to the objectRegistry of the timeVaryingMappedFixedValueFvPatchField that is instanciated, right ?

Given the name of a patch with inletPatchName = "cyclic" , how can I get its objectRegistry, to create an IOobject and output the values at boundary ?

Any help appreciated, even if just to point on how objectRegistry works... I am getting stuck on this problem...

Thanks,

J.D.

mattijs January 15, 2008 12:57

The objectRegistry (this->db()
 
The objectRegistry (this->db()) is the polyMesh i.e. 'mesh' in your top-level application.

db.time() is the Time object, i.e. 'runTime' in your top-level application.

Create a pointIOField (in two steps for clarity reasons), fill it and write it.

IOobject io
(
"points",
runTime.constant(),
"boundaryData"/"cyclic",
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
);

pointIOField samplePoints(io, 100);
samplePoints[0] = 0.0;
..
samplePoints[99] = 0.0;

samplePoints.write();


This is the simplistic use of ioobject. With different settings it allow you to
- register the object on the polyMesh
- so as to have automatic writing
Have a look at how e.g. volXXXfields are created.

johndeas January 16, 2008 08:24

I rewrote your example as :
 
I rewrote your example as :

IOobject io
(
"points",
runTime.constant()/"boundaryData"/"cyclic",
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
);

pointIOField samplePoints(io, 2);
samplePoints[0] = 0.0;
samplePoints[1] = 0.0;

samplePoints.write();

and get the following error:

sandFoam.C:174: error: no match for 'operator=' in 'samplePoints.Foam::IOField<foam::vector<double> >::<anonymous>.Foam::Field<foam::vector<double> >::<anonymous>.Foam::List<foam::vector<double> >::<anonymous>.Foam::UList<t>::operator[] [with T = Foam::Vector<double>](0) = 0.0'
/home/vinz/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude/Vector.H:62: note: candidates are: Foam::Vector<double>& Foam::Vector<double>::operator=(const Foam::Vector<double>&)

I also do not understand how to create fields that exist on a subpart of the mesh and with wich I would like to use IOobject (my boundaries).

My problem is very similar to this one: http://www.cfd-online.com/OpenFOAM_D...tml?1113927929 in the sense that I would not like to code loops and generate boundaryData files myself, but use the OF librairies.

I do not know if I am really clear in what I want to do

mattijs January 17, 2008 15:45

My example was incorrect - jus
 
My example was incorrect - just typed it in. samplePoints is an array of points so you can't assign e.g 0.0 to it. Instead

samplePoints[0] = point(0,0,0);

lourens January 18, 2008 04:48

Hi all, I wrote a simple sc
 
Hi all,

I wrote a simple script (using awk) to convert time series resulting from probes as defined in controlDict to the input for the TimeVaryingMappedFixedValue function. For the moment I hardcoded the variables to convert in the script. It creates a directory BoundaryData, in which the directories for the different times are located. It reads the data from the directory "starttime" in "probes" where starttime has to be specified inthe commandline (probesToTimes root case starttime).
I hope it is usefull for somebody.

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif ProbesToTimes

Regards,

Lourens

johndeas May 22, 2008 11:02

Hi, if I create an AverageIOFi
 
Hi, if I create an AverageIOField this way:

AverageIOField<vector> writeU
(
IOobject
(
"values",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
vector(0.1,0,0), // dummy vector for average value
U.boundaryField()[outletName]
);

I get the following compilation error:

/home/flurec/commun/OpenFOAM/1.4.1-dev/OpenFOAM-1.4.1-dev/src/finiteVolume/lnInc lude/AverageIOField.C: In constructor 'Foam::AverageIOField<type>::AverageIOField(const Foam::IOobject&, const Type&, const Foam::Field<type>&) [with Type = Foam::Vector<double>]':
dpIcoFoamAdimWrite.C:84: instantiated from here
/home/flurec/commun/OpenFOAM/1.4.1-dev/OpenFOAM-1.4.1-dev/src/finiteVolume/lnInc lude/AverageIOField.C:73: error: no matching function for call to 'Foam::pTraits<foam::vector<double> >::pTraits(const Foam::Vector<double>&)'
/home/flurec/commun/OpenFOAM/1.4.1-dev/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude /pTraits.H:56: note: candidates are: Foam::pTraits<primitive>::pTraits(Foam::Istream&) [with primitive = Foam::Vector<double>]
/home/flurec/commun/OpenFOAM/1.4.1-dev/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude /pTraits.H:52: note: Foam::pTraits<foam::vector<double> >::pTraits(const Foam::pTraits<foam::vector<double> >&)
make: *** [Make/linuxGccDPOpt/dpIcoFoamAdimWrite.o] Erreur 1

I am not quit sure how to modify this to get it to work with vectors.

johndeas May 28, 2008 09:34

And, if I use AverageIOFiel
 
And, if I use

AverageIOField writeFlds
(
IOobject
(
"cutPlaneU",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
vector(0.66666666,0,0),
vectorFlds[i].internalField()
);

I get this error : icoFoamWrite.C:149: error: missing template arguments before 'writeFlds'

niklas May 28, 2008 09:50

AverageIOField ...
 
AverageIOField<vector>

...

johndeas May 28, 2008 09:52

... Which gives me the error m
 
... Which gives me the error mentioned one post above

niklas May 28, 2008 10:39

looking the the pTraits.H file
 
looking the the pTraits.H file I only
see an Istream constructor

pTraits(Istream& is)
:
primitive(is)
{}

so I think that's why it wont work with vector(0.6.....)

I dont know how to solve this, but looking at the various constructors this worked (although I dont know if thats an acceptable solution)


AverageIOField<vector> writeU
(
IOobject
(
"values",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
)
);

mattijs May 29, 2008 04:42

You could add a constructor fr
 
You could add a constructor from primitive to pTraits.H

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif pTraits.H

johndeas May 29, 2008 06:45

I modified it, and tried to wm
 
I modified it, and tried to wmake src/OpenFOAM. There are no problem related to pTraits. All the intermediary .o are correctly built. However, when it comes to linking everything, I get:

g++ -m32 -Dlinux -DDP -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-40 -DWM_PROJECT_VERSION='"'1.4.1'"' -I/home/vinz/OpenFOAM/OpenFOAM-1.4.1/src/zlib-1.2.1 -IlnInclude -I. -I/home/vinz/OpenFOAM/OpenFOAM-1.4.1/src/OpenFOAM/lnInclude -fPIC -pthread Make/linuxGccDPOpt/sigFpe.o Make/linuxGccDPOpt/sigSegv.o Make/linuxGccDPOpt/sigInt.o
[...]
Make/linuxGccDPOpt/MeshWaveName.o Make/linuxGccDPOpt/FaceCellWaveName.o Make/linuxGccDPOpt/curve.o Make/linuxGccDPOpt/graph.o Make/linuxGccDPOpt/rawGraph.o Make/linuxGccDPOpt/gnuplotGraph.o Make/linuxGccDPOpt/xmgrGraph.o Make/linuxGccDPOpt/jplotGraph.o -L/home/vinz/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt \
-lOpenFOAM -ldl -lm -o OpenFOAM.out
/usr/lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [OpenFOAM.out] Error 1

Sorry if I abuse readers time, but I am completely lost at this point...

JD

niklas May 29, 2008 07:03

wmake is for compiling applica
 
wmake is for compiling applications.
use wmake libso

johndeas May 29, 2008 07:11

thank you
 
thank you

johndeas December 4, 2008 10:50

Hi, I still got problems re
 
Hi,

I still got problems related to pTraits :

I tried to modify my code in order to export other variables than U (k and p for instance).

This expression will compile:

AverageIOField<vector> writeSampleU
(
IOobject
(
"U",
mesh.time().constant(),
"boundaryData/entree"/runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
U[0],
combinedVecU
);

But, as soon as I want to insert this one:

AverageIOField<scalar> writeSampleP
(
IOobject
(
"p",
mesh.time().constant(),
"boundaryData/entree"/runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
p[0],
combinedScaP
);

I get a nice:

/home/flurec/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/AverageIOField.C: In constructor 'Foam::AverageIOField<type>::AverageIOField(const Foam::IOobject&, const Type&, const Foam::Field<type>&) [with Type = double]':
writeSampleP.H:39: instantiated from here
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/AverageIOField.C:7 3: error: no matching function for call to 'Foam::pTraits<double>::pTraits(const double&)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/Scalar.H:68: note: candidates are: Foam::pTraits<double>::pTraits(Foam::Istream&)
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/Scalar.H:41: note: Foam::pTraits<double>::pTraits(const Foam::pTraits<double>&)
writeSampleP.H:39: instantiated from here
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/AverageIOField.C:7 7: error: invalid static_cast from type 'Foam::AverageIOField<double>' to type 'double&'

From my understanding of template specialization, in Scalar.H:68, when the template pTraits is specialized for scalars, its only constructor is pTraits(Istream& is)

Therefore, the general constructor from primitive:

pTraits(const primitive& p)
:
primitive(p)
{}

which has been added in this forum thread is not available. Should I modify Scalar.H and Scalar.C to get my code to compile ?

adding to Scalar.H :

pTraits(const primitive& p);

adding to Scalar.C :

pTraits<scalar>::pTraits(const primitive& p)
{
p_ = p;
}

panda60 April 2, 2010 12:07

Dear Mattijs and John Deas,
Do you have some common on how to use TimeVaryingMappedFixedValue boundary condition ?
I have two questions:
1.what's the meaning of Average in its input data ?
FoamFile
{
version 2.0;
format ascii;
class vectorAverageField;
object values;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Average
( 0 0 0 )
//
// Data on points
70
(
//minz
(5.74803 0 0)
(5.74803 0 0)

2. Because the most useful things of this boundary condition is to read a large series of data from file as inlet condition. But its request data is a little strange, how we can generate this kind of data ?
Maybe I can get these data from functionObject surface sampling using pre-simulation. But the sampling data is a little difference from TimeVaryingMappedFixedValue data format, and the sampling result have more folders, so how can do this ?
If we have utility to convert sample data to request data format ?
Thank you very much.

panda60 April 2, 2010 12:10

This is request data format for timeVaryingMappedFixedValue :

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.6 |
| \\ / A nd | Web: http://www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class vectorAverageField;
object values;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Average
( 0 0 0 )
//
// Data on points
70
(
//minz
(5.74803 0 0)
(5.74803 0 0)
(11.3009 0 0)
(13.4518 0 0)
.,.................
)

This is sampling data format :

15408
(
(0.0239436 -6.28249e-05 0.000567144)
(0.0239436 -6.28249e-05 0.000567144)
(0.0712944 -0.00019323 -0.00045317)
(0.0712944 -0.00019323 -0.00045317)
(0.122301 -0.000335644 -0.00117908)
(0.122301 -0.000335644 -0.00117908)
(0.178985 -0.000485735 -0.000847965)
(0.178985 -0.000485735 -0.000847965)
.................................................. ....
)

syavash October 13, 2015 06:33

Quote:

Originally Posted by johndeas (Post 181899)
Hi,

I still got problems related to pTraits :

I tried to modify my code in order to export other variables than U (k and p for instance).

This expression will compile:

AverageIOField<vector> writeSampleU
(
IOobject
(
"U",
mesh.time().constant(),
"boundaryData/entree"/runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
U[0],
combinedVecU
);

But, as soon as I want to insert this one:

AverageIOField<scalar> writeSampleP
(
IOobject
(
"p",
mesh.time().constant(),
"boundaryData/entree"/runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
p[0],
combinedScaP
);

I get a nice:

/home/flurec/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/AverageIOField.C: In constructor 'Foam::AverageIOField<type>::AverageIOField(const Foam::IOobject&, const Type&, const Foam::Field<type>&) [with Type = double]':
writeSampleP.H:39: instantiated from here
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/AverageIOField.C:7 3: error: no matching function for call to 'Foam::pTraits<double>::pTraits(const double&)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/Scalar.H:68: note: candidates are: Foam::pTraits<double>::pTraits(Foam::Istream&)
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/Scalar.H:41: note: Foam::pTraits<double>::pTraits(const Foam::pTraits<double>&)
writeSampleP.H:39: instantiated from here
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/AverageIOField.C:7 7: error: invalid static_cast from type 'Foam::AverageIOField<double>' to type 'double&'

From my understanding of template specialization, in Scalar.H:68, when the template pTraits is specialized for scalars, its only constructor is pTraits(Istream& is)

Therefore, the general constructor from primitive:

pTraits(const primitive& p)
:
primitive(p)
{}

which has been added in this forum thread is not available. Should I modify Scalar.H and Scalar.C to get my code to compile ?

adding to Scalar.H :

pTraits(const primitive& p);

adding to Scalar.C :

pTraits<scalar>::pTraits(const primitive& p)
{
p_ = p;
}

Hi,

I have encountered a very similar problem. I have included the following code within pimpleFoam to write U field at inlet, at each time step to be used later through TimeVaryingMappedFixedValue bc.
Code:

AverageIOField<vector> U2
(
    IOobject
    (
        "U",
        mesh.time().timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    U.boundaryField()[ patchID ]
);

U2.write();

But when compiling, OpenFOAM gives me the following error:

Code:

MypimpleFoam.C: In function ‘int main(int, char**)’:
MypimpleFoam.C:97:4: error: ‘AverageIOField’ was not declared in this scope
    AverageIOField<vector> U2
    ^
MypimpleFoam.C:97:25: error: expected primary-expression before ‘>’ token
    AverageIOField<vector> U2
                        ^
MypimpleFoam.C:108:1: error: ‘U2’ was not declared in this scope
 );
 ^
make: *** [Make/linux64GccDPOpt/MypimpleFoam.o] Error 1

I need to implement AverageIOField because TimeVaryingMappedFixedValue accepts data with this type. How can I resolve this problem??

Thanks,
Syavash

Pilardc91 June 14, 2021 14:56

Problem with TimeVaryingMappedFixedValue
 
I am using a boundary condition for the displacement U called TimeVaryingMappedFixedValue. The definition of this BC is:

"This is a derived traction boundary which reads the time and spatial varying force data (from pressure p and/or stresses  S) and computes the traction load and compatible displacement gradient boundary. This boundary condition is derived from tractionDisplacement + timeVary-ingMappedFixedValue in OpenFOAM. (Li et al. 2020)"

When I get the results for each time, this boundary condition does not do like other boundary conditions that store the list of data in the defined patch. In fact, when I look at one of the files and search for the patch where I have imposed that B.C there is no data (it is at the top). The thing is that in Paraview if it represents them to me and it represents them just in that patch.

My doubts are:

1) why does this happen and why Paraview allows to draw it?

2) When I make the sampleDict (and execute sample) none of the interpolation options let me get the data of U, since it looks for the patch and does not find it. Any idea what I can extract those data from

Thank you very much in advance for your help.


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