CFD Online Logo CFD Online URL
Home > Forums > OpenFOAM Programming & Development

How to add a new volField type

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

Like Tree3Likes
  • 3 Post By bigphil

LinkBack Thread Tools Display Modes
Old   September 20, 2012, 11:39
Default How to add a new volField type
Senior Member
bigphil's Avatar
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 597
Rep Power: 20
bigphil will become famous soon enoughbigphil will become famous soon enough

I would like to create a new volField type called volTensor4thOrderField,

so I have created a primitive called Tensor4thOrder and it works fine and I was able to create a tensor4thOrderField without too much difficulty.

However, now I want to have a volTensor4thOrderField so I added the definition to

and also for the fvPatchFields

But I get lots of compilation errors to do with the fvPatchFields (basicSymmetry, fixedValue ).

Does anyone have any tips or know what files exactly I might have to change to get my volTensor4thOrderField working? If it makes a difference I will be using the field for material properties so I only need the calculated or zeroGradient fvPatchField for it.

Best regards,
bigphil is offline   Reply With Quote

Old   September 21, 2012, 11:55
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 424
Rep Power: 14
marupio is on a distinguished road
I could be wrong, but I think it is a much more involved process than just creating the primitive and adding the lines to volFields. You may have to define template specialization behaviour for all mathematical operations. I think all this work has already been done in OpenFOAM-extend with the VectorN library. I think you can just use its VectorN with N set to however many elements there are in your tensor.
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   September 21, 2012, 12:49
Senior Member
bigphil's Avatar
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 597
Rep Power: 20
bigphil will become famous soon enoughbigphil will become famous soon enough
Hi David,

thanks for your reply.

Yep it looks like I have to add a lot of things if I want it to work.

I have tried the VectorN library previously but the problem is that it would not work for my purpose and would be far too memory inefficient.
A fourth order tensor could be visualised as a 9x9 matrix but the definitions of the operators (dot product, double dot, etc) are not the same. Also in my case due to symmetries the fourth order tensor typically only has nine independent values, so the tensor4thOrder only stores 9 values.

I think the work-around I will have to do is to store the internalField cells in a List and the boundaries in a ListList, which is a bit annoying. It would be much more elegant if I could have a volTensor4thOrderField.

I will look into defining the template specialisation for all operations. Looking through the VectorN library is probably a good place to start. If you have tips, I'd love to hear.

bigphil is offline   Reply With Quote

Old   September 28, 2012, 14:35
Senior Member
kmooney's Avatar
Kyle Mooney
Join Date: Jul 2009
Location: Amherst, MA USA - San Diego, CA USA
Posts: 313
Rep Power: 9
kmooney is on a distinguished road
You might be able to store it as a few vector fields (if 9 unique components perhaps 3 vector fields) and write your own operator functions.

something like:


I'd imagine writing explicit formulations would be straightforward, not so much for implicit...
kmooney is offline   Reply With Quote

Old   October 16, 2012, 16:08
Senior Member
bigphil's Avatar
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 597
Rep Power: 20
bigphil will become famous soon enoughbigphil will become famous soon enough
Thanks for the suggestions,

I have been able to create a new primitive type and then create a new volField. There are many files that need to be edited in $FOAM_SRC/OpenFOAM and $FOAM_SRC/finiteVolume.

For anyone else who would like to know, here are the files I had to edit:

./BlockLduInterfaceFields.C:defineTemplateTypeNameAndDebug(BlockLduInterfaceField<sphericalTensor>, 0);
./DimensionedFields.H:#include "DimensionedSphericalTensorField.H"
./FieldFields.H:#include "sphericalTensorFieldField.H"
./GenericPointPatchField.C:                     == token::Compound<List<sphericalTensor> >::typeName NOT DONE RIGHT
./GenericPointPatchField.H:        HashPtrTable<sphericalTensorField> sphericalTensorFields_;
./GeometricFields.H:#include "GeometricSphericalTensorField.H"
./PointPatchField.H:makePointPatchTypeFieldTypeName(typePatchField##pointPatchType##SphericalTensorField); \
./Random.C:sphericalTensor Random::sphericalTensor01()
./Random.H:        //- sphericalTensor with every component scalar01
./dimensionedTypes.H:#include "dimensionedSphericalTensor.H"
./fieldTypes.H:#include "sphericalTensor.H"
./pointFields.C:defineTemplateTypeNameAndDebug(pointSphericalTensorField::DimensionedInternalField, 0);
./pointFieldsFwd.H:typedef GeometricField<sphericalTensor, pointPatchField, pointMesh>
./pointMesh.C:        sphericalTensor,
./pointPatchFields.C:<pointPatchField, pointMesh, pointPatch, DummyMatrix, sphericalTensor>
./pointPatchFieldsFwd.H:typedef pointPatchField<sphericalTensor> pointPatchSphericalTensorField;
./primitiveFields.H:#include "sphericalTensorField.H"
./primitiveFieldsFwd.H:typedef Field<sphericalTensor> sphericalTensorField;
./symmTransform.H:inline SphericalTensor<Cmpt> transform
./transform.H:inline SphericalTensor<Cmpt> transform
./uniformDimensionedFields.C:defineTemplateTypeNameAndDebug(uniformDimensionedSphericalTensorField, 0);
./uniformDimensionedFields.H:typedef UniformDimensionedField<sphericalTensor> uniformDimensionedSphericalTensorField;
./transformField.H:99:tmp<Field<tensor4thOrder> > transformFieldMask<tensor4thOrder>
in $FOAM_SRC/finiteVolume:
AverageIOFields.C:41:typedef AverageIOField<tensor4thOrder> tensor4thOrderAverageIOField;
d2dt2Scheme.H:199:makeFvD2dt2TypeScheme(SS, tensor4thOrder)
d2dt2Schemes.C:49:defineTemplateRunTimeSelectionTable(d2dt2Scheme<tensor4thOrder>, Istream);
ddtScheme.H:259:makeFvDdtTypeScheme(SS, tensor4thOrder)                                        \
ddtSchemes.C:49:defineTemplateRunTimeSelectionTable(ddtScheme<tensor4thOrder>, Istream);
divScheme.H:182:makeFvDivTypeScheme(SS, tensor4thOrder)                                       \
divSchemes.C:65:    divScheme<tensor4thOrder>,
fvMatrices.C:43:defineTemplateTypeNameAndDebug(fvTensor4thOrderMatrix, 0);
fvMatricesFwd.H:55:typedef fvMatrix<tensor4thOrder> fvTensor4thOrderMatrix;
fvMesh.C:446:    MapGeometricFields<tensor4thOrder, fvPatchField, fvMeshMapper, volMesh>
fvPatchField.H:501:makePatchTypeFieldTypeName(type##FvPatchTensor4thOrderField);              \
fvPatchFieldsFwd.H:45:typedef fvPatchField<tensor4thOrder> fvPatchTensor4thOrderField;
fvsPatchField.H:390:makeFvsPatchTypeFieldTypeName(type##FvsPatchTensor4thOrderField);          \
fvsPatchFieldsFwd.H:50:typedef fvsPatchField<tensor4thOrder> fvsPatchTensor4thOrderField;
genericFvPatchField.C:503:        HashPtrTable<tensor4thOrderField>::const_iterator iter =
genericFvPatchField.H:65:        HashPtrTable<tensor4thOrderField> tensor4thOrderFields_;
interpolation.H:161:makeInterpolationType(SS, tensor4thOrder)                                      \
interpolations.C:43:defineTemplateRunTimeSelectionTable(interpolation<tensor4thOrder>, dictionary);
limitedSurfaceInterpolationScheme.H:227:makelimitedSurfaceInterpolationTypeScheme(SS, tensor4thOrder)
slicedSurfaceFieldsFwd.H:76:SlicedGeometricField<tensor4thOrder, fvsPatchField, slicedFvsPatchField, surfaceMesh>
slicedVolFieldsFwd.H:77:SlicedGeometricField<tensor4thOrder, fvPatchField, slicedFvPatchField, volMesh>
snGradScheme.H:198:makeSnGradTypeScheme(SS, tensor4thOrder)
snGradSchemes.C:50:defineTemplateRunTimeSelectionTable(snGradScheme<tensor4thOrder>, Mesh);
surfaceFields.C:40:defineTemplateTypeNameAndDebug(surfaceTensor4thOrderField::DimensionedInternalField, 0);
surfaceFieldsFwd.H:61:typedef GeometricField<tensor4thOrder, fvsPatchField, surfaceMesh>
surfaceInterpolationScheme.H:230:makeSurfaceInterpolationTypeScheme(SS, tensor4thOrder)                         \
volFields.C:40:defineTemplateTypeNameAndDebug(volTensor4thOrderField::DimensionedInternalField, 0);
volFieldsFwd.H:60:typedef GeometricField<tensor4thOrder, fvPatchField, volMesh> volTensor4thOrderField;
and I had to add files for my new primitive which are equivalent to the following files (in $FOAM_SRC/OpenFOAM):
./DimensionedSphericalTensorField.C:#include "DimensionedSphericalTensorField.H"
./DimensionedSphericalTensorField.H:    Foam::DimensionedSphericalTensorField
./GeometricSphericalTensorField.C:#include "GeometricSphericalTensorField.H"
./GeometricSphericalTensorField.H:    Foam::GeometricSphericalTensorField
./SphericalTensor.H:    Foam::SphericalTensor
./SphericalTensorI.H:inline SphericalTensor<Cmpt>::SphericalTensor()
./dimensionedSphericalTensor.C:    Dimensioned sphericalTensor obtained from generic dimensioned type.
./dimensionedSphericalTensor.H:dimensionedSphericalTensor inv(const dimensionedSphericalTensor&);
./labelSphericalTensor.C:#include "labelSphericalTensor.H"
./labelSphericalTensor.H:inline bool contiguous<labelSphericalTensor>() {return true;}
./sphericalTensor.C:#include "sphericalTensor.H"
./sphericalTensor.H:    Foam::sphericalTensor
./sphericalTensorField.C:#include "sphericalTensorField.H"
./sphericalTensorField.H:    Foam::sphericalTensorField
./sphericalTensorFieldField.C:    Specialisation of FieldField<Field, T> for sphericalTensor.
./sphericalTensorFieldField.H:    Foam::sphericalTensorFieldField
./sphericalTensorIOField.C:    sphericalTensorField with IO.
./sphericalTensorIOField.H:    Foam::sphericalTensorIOField
./sphericalTensorList.C:    Specialisation of List\<T\> for sphericalTensor.
./sphericalTensorList.H:    Foam::sphericalTensorList
I found the files I needed by find all files with with the string sphericalTensor and then I essentially did the same for my new class.

Phew, and that's it!

hua1015, Surly and mbookin like this.
bigphil is offline   Reply With Quote


Thread Tools
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM 300 October 29, 2014 19:00
Air Conditioned room groovyBC Sebaj OpenFOAM 7 October 31, 2012 15:16
cgnsToFoam problems with "QUAD_4" cells lentschi OpenFOAM Meshing & Mesh Conversion 1 March 9, 2011 05:49
turbulent jet simulation antonio_ing OpenFOAM Running, Solving & CFD 5 September 16, 2010 02:31
reconstructParMesh not working with an axisymetric case francesco OpenFOAM Bugs 4 May 8, 2009 05:49

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