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

How to keep an initial field created by setFields during the simulation

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By geth03

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 17, 2024, 20:14
Default How to keep an initial field created by setFields during the simulation
  #1
New Member
 
Rafael Gabler
Join Date: Feb 2024
Posts: 4
Rep Power: 2
rafaelgabler is on a distinguished road
Hello everyone!

I'm a new openFoam user and I'm trying to produce a solver based on the scalarTransportFoam that solves the energy equation in a biological medium containing a region with a tumour surrounded by a healthy tissue area.

My idea was to use the setFields to define the region of the tumour using an identifier, ID, which is 0 in the healthy tissue region and 1 inside the tumour region.

This identifier was defined as a volscalarField in my createFields.H file in the solver.

I also created an additional file named Weqn.H, which computes the blood perfusion field W using different algebric expresions according to the region that the volume occupies inside the mesh.

When I run the blockMesh command followed by setFields, the initial ID field is ok. However, when the solver executes the simulation my ID field is replaced by a null field during the time evolution process.

I would like to keep the ID field on the 0 folder, created through the setFields during the whole temporal loop of the simulation.

Any ideas of how can I achieve this goal?

Thanks in advance!

Best Regards!
rafaelgabler is offline   Reply With Quote

Old   February 18, 2024, 21:08
Default Additional information
  #2
New Member
 
Rafael Gabler
Join Date: Feb 2024
Posts: 4
Rep Power: 2
rafaelgabler is on a distinguished road
Another ideia would be to call in the assemblying of the matrices for the linear system responsible for solving the temperature only the values of this identifier on the 0 folder.

Here is the piece of code I'm using to mount my energy equation:

fvScalarMatrix TEqn
(
fvm::ddt(T)
+ fvm::div(phi, T)
- fvm::laplacian(DT, T)
==
fvOptions(T) + ID*mu0*pi*H0*H0*freq*qui_imag*corr/(rho*cp)
+ rhob*cb*W*(T-Tb)/(rho*cp)
);

I would like to call the ID field always from the zero folder.

Any ideia on how to do this?

I feel that this should be a really simple thing to do, but I'm new in this OpenFOAM Universe and have no idea of what would be the proper synthax to do this.

If anyone could help me I would be very happy!
rafaelgabler is offline   Reply With Quote

Old   February 19, 2024, 07:25
Default
  #3
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 367
Rep Power: 8
geth03 is on a distinguished road
i am not sure if i understand what you are trying to do.

however, you might want to create a cellZone in which your "ID" is set to a constant value. and your equation picks up that value accordingly.
so your "ID"-value would remain independent of time evolution.

if that is what you want you can give a feedback.
rafaelgabler likes this.
geth03 is offline   Reply With Quote

Old   February 19, 2024, 18:09
Default Problem solved
  #4
New Member
 
Rafael Gabler
Join Date: Feb 2024
Posts: 4
Rep Power: 2
rafaelgabler is on a distinguished road
Thanks a lot for your repply, geth03.

I will take a look in the cellZone documentation.

I figured out that my problem was in another piece of the code.

The solution for my problem envolved the following steps:

1 - I created a volScalarField to storage the identifier ID in the createFields.H:

volScalarField ID
(
IOobject
(
"ID",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

2 - Then I configured the setFieldsdict to produce this initial field and called it in the assembly of my linear system for temperature using the .internalField() atributte, which was something I did not know how to call it at the beggining and took a really long time to figure out.

fvScalarMatrix TEqn
(
fvm::ddt(T)
+ fvm::div(phi, T)
- fvm::laplacian(DT, T)
- ID.internalField()*mu0*pi*H0*H0*freq*qui_imag*corr/(rho*cp)
==
fvOptions(T)
+ rhob*cb*W.internalField()*(T-Tb)/(rho*cp)
);

Now the simulations are running as expected.

Thank you very much for your reply. I would like to learn how to create a cellZone in this case and how to call it. This could be useful in other steps of my project.

Best Regards!

Quote:
Originally Posted by geth03 View Post
i am not sure if i understand what you are trying to do.

however, you might want to create a cellZone in which your "ID" is set to a constant value. and your equation picks up that value accordingly.
so your "ID"-value would remain independent of time evolution.

if that is what you want you can give a feedback.
rafaelgabler is offline   Reply With Quote

Old   February 20, 2024, 10:57
Default
  #5
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 367
Rep Power: 8
geth03 is on a distinguished road
i wanted to suggest another solution, that is basically similar to what you did but instead of setFields i wanted to do it with cellZone. a cellZone is basically a declaration of a zone in your mesh which you can access in your code for further calculations.

but i am glad you found a workaround.
geth03 is offline   Reply With Quote

Old   February 20, 2024, 15:54
Default Correction
  #6
New Member
 
Rafael Gabler
Join Date: Feb 2024
Posts: 4
Rep Power: 2
rafaelgabler is on a distinguished road
Just a correction. In this quoted piece of code, ID.internalField() and W.internalField() should be simply replaced by ID and W in the assemblying of the temperature linear system.

The code seems to work fine, except for very low values of the thermal diffusivity DT. When I decrease my DT value bellow a certain limit (which I would like to reach) the solver does not run.

I'm using a Gauss linear corrected scheme for the Laplacian on the fvSchemes.

Any ideas?

Quote:
Originally Posted by rafaelgabler View Post
Thanks a lot for your repply, geth03.

I will take a look in the cellZone documentation.

I figured out that my problem was in another piece of the code.

The solution for my problem envolved the following steps:

1 - I created a volScalarField to storage the identifier ID in the createFields.H:

volScalarField ID
(
IOobject
(
"ID",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

2 - Then I configured the setFieldsdict to produce this initial field and called it in the assembly of my linear system for temperature using the .internalField() atributte, which was something I did not know how to call it at the beggining and took a really long time to figure out.

fvScalarMatrix TEqn
(
fvm::ddt(T)
+ fvm::div(phi, T)
- fvm::laplacian(DT, T)
- ID.internalField()*mu0*pi*H0*H0*freq*qui_imag*corr/(rho*cp)
==
fvOptions(T)
+ rhob*cb*W.internalField()*(T-Tb)/(rho*cp)
);

Now the simulations are running as expected.

Thank you very much for your reply. I would like to learn how to create a cellZone in this case and how to call it. This could be useful in other steps of my project.

Best Regards!
rafaelgabler is offline   Reply With Quote

Old   February 21, 2024, 13:13
Default
  #7
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 367
Rep Power: 8
geth03 is on a distinguished road
If you add terms to your equation you should decide if you want to add to the matrix or to the source, if you make wrong decisions your system will be hard to converge or even don‘t run.

Your implementation right now will put everything to the source. It can be possible that for low DT your matrix is not diagonally dominant. To offset this, you might decrease your time step.
geth03 is offline   Reply With Quote

Reply

Tags
setfields


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
Help sought on axial compressor simulation jyotir OpenFOAM Running, Solving & CFD 0 November 17, 2021 11:49
Suppress twoPhaseEulerFoam energy AlmostSurelyRob OpenFOAM Running, Solving & CFD 33 September 25, 2018 18:45
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 12 August 4, 2015 03:20
calculation stops after few time steps sivakumar OpenFOAM Running, Solving & CFD 7 March 17, 2013 07:37
Error while running rhoPisoFoam.. nileshjrane OpenFOAM Running, Solving & CFD 8 August 26, 2010 13:50


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