CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to add a new volField type (http://www.cfd-online.com/Forums/openfoam-programming-development/107223-how-add-new-volfield-type.html)

bigphil September 20, 2012 11:39

How to add a new volField type
 
Hi,

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
finiteVolume/fields/volFields/volFields.C
and
finiteVolume/fields/volFields/volFieldsFwd.C

and also for the fvPatchFields
finiteVolume/fields/fvPatchField/fvPatchField/fvPatchFieldsFwd.C
and
finiteVolume/fields/fvPatchField/fvPatchField/fvPatchFields.C

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,
Philip

marupio September 21, 2012 11:55

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.

bigphil September 21, 2012 12:49

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.

Thanks,
Philip

kmooney September 28, 2012 14:35

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:

addOperator(vF1,vF2,vF3)
subtractionOperator(vF1,vF2,vF3)

I'd imagine writing explicit formulations would be straightforward, not so much for implicit...

bigphil October 16, 2012 16:08

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:

in $FOAM_SRC/OpenFOAM
Code:

./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:
Code:

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);              \
fvPatchFields.C:52:makeFvPatchField(fvPatchTensor4thOrderField)
fvPatchFieldsFwd.H:45:typedef fvPatchField<tensor4thOrder> fvPatchTensor4thOrderField;
fvsPatchField.H:390:makeFvsPatchTypeFieldTypeName(type##FvsPatchTensor4thOrderField);          \
fvsPatchFields.C:52:makeFvsPatchField(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)
limitedSurfaceInterpolationSchemes.C:56:makeBaseLimitedSurfaceInterpolationScheme(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)                        \
surfaceInterpolationSchemes.C:56:makeBaseSurfaceInterpolationScheme(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):
Code:

./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!

Philip

ZhoujiangZho May 17, 2016 08:01

Dear Philip,
Could you explain some details about how to generate a new volTensor4thOrderfield in OpenFOAM? Thanks for your work here!! I also need this volTensor4thOrderfield to generate a tensor regarding elastoplastic stress strain relationship.
Thank you very much!!
Best Regards
Zhoujiang Deng

ZhoujiangZho May 17, 2016 08:02

Dear Philip,
Could you explain some details about how to generate a new volTensor4thOrderfield in OpenFOAM? Thanks for your work here!! I also need this volTensor4thOrderfield to generate a tensor regarding elastoplastic stress strain relationship.
Thank you very much!!
Best Regards
Zhoujiang Deng


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