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/)
-   -   timeVaryingMappedFixedValueFvPatchField for Traction control at boundaries (http://www.cfd-online.com/Forums/openfoam-programming-development/92561-timevaryingmappedfixedvaluefvpatchfield-traction-control-boundaries.html)

Hisham September 18, 2011 09:34

timeVaryingMappedFixedValueFvPatchField for Traction control at boundaries
 
Dear Foamers,

Using the solidDisplacementFoam, I need to introduce a timeVaryingMappedFixedValue -like BC for traction. As far as I know, the tractionDisplacement BC supports integration over neither time nor space. However, I am not so sure what the autoMap and rmap functions do exactly!

If there were any such BC out there, I would highly appreciate it if it were to be shared :)

Else, to introduce such BC, what do you suggest I should start with? I found this groovyTractionDisplacementBC and I thought to use it as a guideline. Any help or advice is appreciated.

Thanks in advance and best regards,
Hisham

Hisham September 18, 2011 11:48

I think I'll copy the timeVaryingMappedFixedValue BC files, rename them and let them inhere tractionDisplacementFvPatchVectorField to use it's autoMap, rmap, updateCoeffs & write functions. I would, then, "untemplate" the functions and modify them for a tractionDisplacementFvPatchField instead of a fixedValue one. Am I planning in the right direction????

bigphil September 18, 2011 12:38

Hi Hisham,

Using groovyTractionDisplacementBC would be the easiest option, it will give you a time-varying traction boundary condition.

tractionDisplacementFvPatchField derives from a fixedGradientFvPatchField so you would need to start with some sort of timeVaryingMappedFixedGradient boundary condition, but I think this would be quite a bit of effort so groovy is a more straight forward option.

Philip

Hisham September 18, 2011 13:00

Hi Phillip

My problem is that I have a random time series for traction/pressure that is, also, not uniform (also random) all over the patch. Therefore, I need some space and time interpolation and hence I am thinking of using timeVaryingMappedFixedValue as a base for a new BC and to replace whatever fixed value patch field with a traction Displacement one which inherits a fixed gradient patch by default.

Is it possible to use groovyBC in my case? Can you elaborate please!

Thanks
Hisham

bigphil September 18, 2011 13:18

Hisham,


You want your boundary to vary in time AND space, OK I don't think the current groovyTractionDisplacement can do that at the moment (but could probably be altered to do this).

I think the easiest way for you to achieve what you want would be to create a header file in the time loop that updates your boundary conditions. The header file should be something like the following:

Code:

label patchID = mesh.boundaryMesh().findPatchID("patch_of_interest");

if(patchID == -1)
  {
      Info << "Patch of interest not found." << endl;
      return 0;
    }


tractionDisplacementFvPatchVectorField& Dpatch =
refCast<tractionDisplacementFvPatchVectorField>
  (
      D.boundaryField()[patchID]
    );

vectorField patchFaceCentres = mesh.boundaryMesh()[patchID].faceCentres();

forAll(Dpatch.traction(), facei)
{
        Dpatch.traction()[facei] = runTime.value() * patchFaceCentres[facei];
}

This code will set the traction on each patch face as some function of time and the patch face position. Obviously you set the traction however you would like, I was just giving an example traction to set.


Philip

Hisham September 18, 2011 16:12

I got the error:

Quote:

error: ‘tractionDisplacementFvPatchVectorField’ was not declared in this scope
I tried to include the tractionDisplacement header but then got "Additional" errors:
Quote:

In file included from /opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchFields.H:29:0,
from tractionDisplacement/tractionDisplacementFvPatchVectorField.H:40,
from Try.H:1,
from geotechFoam.C:100:
/opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchField.H: In function ‘int main(int, char**)’:
/opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchField.H:42:1: error: ‘namespace’ definition is not allowed here
In file included from /opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchField.H:208:0,
from /opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchFields.H:29,
from tractionDisplacement/tractionDisplacementFvPatchVectorField.H:40,
from Try.H:1,

I have no clue to what I'm doing wrong.

Also, what is the Upatch in the forAll loop?

bigphil September 19, 2011 04:49

Hisham,


Quote:

Originally Posted by Hisham (Post 324587)
I tried to include the tractionDisplacement header but then got "Additional" errors:

If you include the following line at the top of your solver:
Code:

#include "tractionDisplacementFvPatchVectorField.H"

Quote:

Originally Posted by Hisham (Post 324587)
Also, what is the Upatch in the forAll loop?

Sorry the Upatch is meant to be "Dpatch". (In my solvers I call the displacement variable U.)

If it still doesn't compile then paste the full compilation log here.


Philip

Hisham September 19, 2011 11:48

Philip,

The include line is:
Quote:

#include "tractionDisplacement/tractionDisplacementFvPatchVectorField.H"
The error I get after a wclean all - wmake all

Quote:

hisham@hisham-Aspire-6930G:~/OpenFOAM/hisham-2.0.1/geotechFoam$ wclean all
wclean ./
hisham@hisham-Aspire-6930G:~/OpenFOAM/hisham-2.0.1/geotechFoam$ wmake all
Making dependency list for source file tractionDisplacement/tractionDisplacementFvPatchVectorField.C
Making dependency list for source file geotechFoam.C
SOURCE=tractionDisplacement/tractionDisplacementFvPatchVectorField.C ; g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam201/src/finiteVolume/lnInclude -ItractionDisplacement/lnInclude -IlnInclude -I. -I/opt/openfoam201/src/OpenFOAM/lnInclude -I/opt/openfoam201/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linuxGccDPOpt/tractionDisplacementFvPatchVectorField.o
SOURCE=geotechFoam.C ; g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam201/src/finiteVolume/lnInclude -ItractionDisplacement/lnInclude -IlnInclude -I. -I/opt/openfoam201/src/OpenFOAM/lnInclude -I/opt/openfoam201/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linuxGccDPOpt/geotechFoam.o
In file included from /opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchFields.H:29:0,
from tractionDisplacement/tractionDisplacementFvPatchVectorField.H:40,
from geotechFoam.C:85:
/opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchField.H: In function ‘int main(int, char**)’:
/opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchField.H:42:1: error: ‘namespace’ definition is not allowed here
In file included from /opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchField.H:208:0,
from /opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchFields.H:29,
from tractionDisplacement/tractionDisplacementFvPatchVectorField.H:40,
from geotechFoam.C:85:
/opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchField.C:31:1: error: ‘namespace’ definition is not allowed here
In file included from tractionDisplacement/tractionDisplacementFvPatchVectorField.H:40:0,
from geotechFoam.C:85:
/opt/openfoam201/src/finiteVolume/lnInclude/fixedGradientFvPatchFields.H:34:1: error: ‘namespace’ definition is not allowed here
In file included from geotechFoam.C:85:0:
tractionDisplacement/tractionDisplacementFvPatchVectorField.H:44:1: error: ‘namespace’ definition is not allowed here
In file included from geotechFoam.C:100:0:
Try.H:4:1: error: ‘tractionDisplacementFvPatchVectorField’ was not declared in this scope
Try.H:4:41: error: ‘Dpatch’ was not declared in this scope
Try.H:5:13: error: ‘tractionDisplacementFvPatchVectorField’ cannot appear in a constant-expression
Try.H:8:5: error: no matching function for call to ‘refCast(Foam::fvPatchField<Foam::Vector<double> >&)’
readGeotechFoamControls.H:3:11: warning: unused variable ‘nCorr’
readGeotechFoamControls.H:5:29: warning: unused variable ‘convergenceTolerance’
geotechFoam.C:111:13: warning: unused variable ‘iCorr’
geotechFoam.C:112:16: warning: unused variable ‘initialResidual’
readGeotechFoamControls.H:3:11: warning: unused variable ‘nCorr’
readGeotechFoamControls.H:5:29: warning: unused variable ‘convergenceTolerance’
make: *** [Make/linuxGccDPOpt/geotechFoam.o] Error 1
hisham@hisham-Aspire-6930G:~/OpenFOAM/hisham-2.0.1/geotechFoam$

bigphil September 19, 2011 12:05

Hisham,


Did you include the traction BC file at the top of your solver? (ie before the main() function NOT inside the main function.

Also normally when I include a BC in my solver I add it to Make/files (ie tractionDisplacementFvPatchVectorField.C) and I use "wclean" and "wmake" to compile the solver and the BC will be automatically linked. I am not sure what "wmake all" does in this situation...

Could you post a "stripped-down" version of your solver here so I can try to compile it?


Philip

Hisham September 19, 2011 12:42

Quote:

Originally Posted by bigphil (Post 324710)

Did you include the traction BC file at the top of your solver? (ie before the main() function NOT inside the main function.

Yes! (EDIT: No, read following answer)

Quote:

Originally Posted by bigphil (Post 324710)
Also normally when I include a BC in my solver I add it to Make/files (ie tractionDisplacementFvPatchVectorField.C)

I believe the tractionDisplacement BC .C file is included in the wmake (files & option) files for the solver before I edit it (it is based on solidDisplacementFoam) or else I'm not following

Quote:

Originally Posted by bigphil (Post 324710)
and I use "wclean" and "wmake" to compile the solver and the BC will be automatically linked. I am not sure what "wmake all" does in this situation...

I guess "wmake all" here is equivalent to wmake as there is only one destination to compile!

Quote:

Originally Posted by bigphil (Post 324710)
Could you post a "stripped-down" version of your solver here so I can try to compile it?

I will as soon as I return to the machine that has the code. Nevertheless, I commented out all lines except the includes, the lines you suggest and the time loop.

Hisham September 19, 2011 12:52

Sorry Philip, you are right. I had, foolishly, misplaced the include inside int Main()

I edited it and it compiled (for solidDisplacementFoam). I will post further info later.

Thanks a lot :)

bigphil September 19, 2011 13:03

Great,

Hopefully it will do what you want.

Philip

Hisham September 19, 2011 13:13

It has worked beautifully. I have another question though! How can I apply that to internal faces? Say I need to define a variable (e.g. displacement) for a face or volume inside the domain.

I want to know how to define an internal face (not a boundary patch) and assign values to its parameters from within the code.

bigphil September 19, 2011 13:30

Hisham,

Hmmnn I am not really sure what you mean by applying a BC to internal face...

The value at an internal face is solved for so you could set the value of D at an internal cell but when you solve the system then the value an this internal face will change.
Maybe I am not quite understanding. Also D is stored (and solved for) at cell centres not faces.
If you really wanted to set the value of D in the internal cells, something like this would do it (but when you solve the equations then these values will be overwritten):
Code:

vectorField cellCentres = mesh.C();
forAll(D.internalField(), celli)
{
  D.internalField()[celli] = cellCentres[celli] * runTime.value() * .....;
}

Philip

Hisham September 19, 2011 13:59

Thanks a lot Philip for your quick responses.

I do not mean the full domain. Just a pre-defined face. For example, I see there is a faceZone and cellZone. I know how to assign cellZones in say blockMesh or Gmsh (sadly I can't say the same for faceZones). How can I retrieve the id of contained or nearest cells "for faceZone case" (or loop them knowing their position) and assign variables to these cells.

I guess it is possible take for example that setFields (funkySetFields) utility can work for time steps other than the initial.

Thanks again
Hisham

gschaider September 19, 2011 14:20

Quote:

Originally Posted by Hisham (Post 324722)
Thanks a lot Philip for your quick responses.

I do not mean the full domain. Just a pre-defined face. For example, I see there is a faceZone and cellZone. I know how to assign cellZones in say blockMesh or Gmsh (sadly I can't say the same for faceZones). How can I retrieve the id of contained or nearest cells "for faceZone case" (or loop them knowing their position) and assign variables to these cells.

I guess it is possible take for example that setFields (setFunkyFields) utility can work for time steps other than the initial.

That is my cue ;)

swak4Foam (which now is the home of funkySetFields) has two possibilities to do that (fix the solution in selected cells):

- the functionObject manipulateField. That overwrites the values of a field in selected cells at the end of each timesteps. That doesn't need a modification of the solver but as the equation is solved for those cells anyway the results may be weird
- an object forceEquation that helps to fix the equations in selected cells before they are solved. You'll have to modify the solver for this (there comes an example of a modified interFoam with swak4Foam). It does so using the setValues-method of the fvMatrix-class (so you can also do that without swak4Foam, but you're on your own here)

Please beware that if used wrongly both of them are ugly hacks and I don't accept responsibility for wrong physics

Bernhard

Hisham September 19, 2011 14:36

Hi Bernhard,

The idea is, for example, if I want to define the temperature inside part of a given domain for a thermal-stress analysis (it is not wrong physically). I am sure (as you said) it is possible to implement such constraint on a numerical solution. I will research the forceEquation option as it seems the proper tool for the task. I will look into swak4Foam for that.

Another thing is: how can I recognize cells for a cellZone or faceZone from inside the code (and their positions). And (if not yet too much to ask) how can I define faceZones in input :confused:

Thanks a lot Bernhard & Philip
Hisham

EDIT: from the gmshToFoam code, it seems that any internal surface defined as physical surface is transformed into a faceZone!


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