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

using setFields to assign different material properties

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 2, 2017, 01:34
Default using setFields to assign different material properties
  #1
Member
 
Saleh Abuhanieh
Join Date: Nov 2017
Posts: 82
Rep Power: 8
Saleh Abuhanieh is on a distinguished road
Hi Foamers,

I am trying to modify the electrostatic solver slightly to be able to read a constant (electric permittivity) with different values from different regions/patches inside the simulation domain.
the solutions which I found were mainly talking about using setField utility.

- Is this the recommended solution?
- If yes, how we can make the solver read it correctly (I am trying now by adding I/O to the createFields.H, it reads but I am not sure if this is the correct way and I have problem with "undefined" variables ) or by making new createFields where I can read from setFieldsDict?

Thank you in advance
Saleh Abuhanieh is offline   Reply With Quote

Old   December 3, 2017, 16:41
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

I would call it easiest and straightforward solution, rather than "recommended".

Post your code, post your error, otherwise it is not clear what modifications you have made.
alexeym is offline   Reply With Quote

Old   December 3, 2017, 22:18
Default
  #3
Member
 
Saleh Abuhanieh
Join Date: Nov 2017
Posts: 82
Rep Power: 8
Saleh Abuhanieh is on a distinguished road
Hi alexeym,

after creating my geometry in Salome, and divide the mesh region using "splitMeshRegions -cellZonesonly -over write", my case folder contains the following:


├── 0
│ ├── cellToRegion
│ ├── epsion
│ ├── phi
│ └── rho
├── constant
│ ├── cellToRegion
│ ├── physicalProperties
│ └── polyMesh
│ ├── boundary
│ ├── cellZones
│ ├── faces
│ ├── neighbour
│ ├── owner
│ └── points
└── system
├── controlDict
├── fvSchemes
├── fvSolution
└── setFieldsDict


the setFieldDict file:

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object setFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

defaultFieldValues
(
volScalarFieldValue epsilon 8.85e-12
);

regions
(
zoneToCell
{
name "SubSimulationDomain_InternalVacuum";

fieldValues
(
volScalarFieldValue epsilon 20e-12
);
}

zoneToCell
{
name "SubSimulationDomain_MetalShields";

fieldValues
(
volScalarFieldValue epsilon 30e-12
);
}


zoneToCell
{
name "SubSimulationDomain_ExternalVacuum";

fieldValues
(
volScalarFieldValue epsilon 40e-12
);
}


zoneToCell
{
name "SubSimulationDomain_Insulator";

fieldValues
(
volScalarFieldValue epsilon 50e-12
);
}


);


// ************************************************** *********************** //

when I run the setFields, I receive the following and nothing happens:


/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev-debug |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : dev-debug-17954fc1734a
Exec : setFields
Date : Dec 04 2017
Time : 05:57:22
Host : "uuuuuu"
PID : 6832
I/O : uncollated
Case : /home/salehabuhanieh/OpenFOAM/salehabuhanieh-dev-debug/run/Case2Run_multiRegion
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading setFieldsDict

Setting field default values
--> FOAM Warning :
From function bool setCellFieldType(const Foam::word&, const Foam::fvMesh&, const labelList&, Foam::Istream&) [with Type = double; Foam::labelList = Foam::List<int>]
in file setFields.C at line 117
Field epsilon not found

Setting field region values
Adding all cells of cellZone SubSimulationDomain_InternalVacuum ...
Found matching zone SubSimulationDomain_InternalVacuum with 42817 cells.
--> FOAM Warning :
From function bool setCellFieldType(const Foam::word&, const Foam::fvMesh&, const labelList&, Foam::Istream&) [with Type = double; Foam::labelList = Foam::List<int>]
in file setFields.C at line 117
Field epsilon not found
Adding all cells of cellZone SubSimulationDomain_MetalShields ...
Found matching zone SubSimulationDomain_MetalShields with 8391 cells.
--> FOAM Warning :
From function bool setCellFieldType(const Foam::word&, const Foam::fvMesh&, const labelList&, Foam::Istream&) [with Type = double; Foam::labelList = Foam::List<int>]
in file setFields.C at line 117
Field epsilon not found
Adding all cells of cellZone SubSimulationDomain_ExternalVacuum ...
Found matching zone SubSimulationDomain_ExternalVacuum with 70862 cells.
--> FOAM Warning :
From function bool setCellFieldType(const Foam::word&, const Foam::fvMesh&, const labelList&, Foam::Istream&) [with Type = double; Foam::labelList = Foam::List<int>]
in file setFields.C at line 117
Field epsilon not found
Adding all cells of cellZone SubSimulationDomain_Insulator ...
Found matching zone SubSimulationDomain_Insulator with 8618 cells.
--> FOAM Warning :
From function bool setCellFieldType(const Foam::word&, const Foam::fvMesh&, const labelList&, Foam::Istream&) [with Type = double; Foam::labelList = Foam::List<int>]
in file setFields.C at line 117
Field epsilon not found

End

in the original case, it was epsilon0 and defined in the physicalProperties file:

*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 5 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object physicalProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

epsilon0 epsilon0 [-1 -3 4 0 0 2 0] 8.85419e-12;

I changed the solver to accept epsilon not epsilon0 nothing more.

The author of this thesis used similar way, (http://webfiles.portal.chalmers.se/e...heHuangMSc.pdf)

If i didn't read the above reference I would have went with the multi region concept like the chtMyltiRegionsSimpleFoam.

I hope my explanation is enough



Saleh Abuhanieh is offline   Reply With Quote

Old   December 4, 2017, 02:37
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

You miss l in epsilon in 0 folder, i.e. in 0 folder you have *epsion* instead of *epsilon*. This causes all those

Code:
--> FOAM Warning : 
From function bool setCellFieldType(const Foam::word&, const Foam::fvMesh&, const labelList&, Foam::Istream&) [with Type = double; Foam::labelList = Foam::List<int>]
in file setFields.C at line 117
Field epsilon not found
alexeym is offline   Reply With Quote

Old   December 4, 2017, 22:33
Default
  #5
Member
 
Saleh Abuhanieh
Join Date: Nov 2017
Posts: 82
Rep Power: 8
Saleh Abuhanieh is on a distinguished road
Hi,

Thank you alexeym.
it was a silly mistake.


now I can execute setFields successfully with the following output:


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading setFieldsDict

Setting field default values
Setting internal values of volScalarField epsilon

Setting field region values
Adding all cells of cellZone SubSimulationDomain_InternalVacuum ...
Found matching zone SubSimulationDomain_InternalVacuum with 42817 cells.
Setting internal values of volScalarField epsilon
Adding all cells of cellZone SubSimulationDomain_MetalShields ...
Found matching zone SubSimulationDomain_MetalShields with 8391 cells.
Setting internal values of volScalarField epsilon
Adding all cells of cellZone SubSimulationDomain_ExternalVacuum ...
Found matching zone SubSimulationDomain_ExternalVacuum with 70862 cells.
Setting internal values of volScalarField epsilon
Adding all cells of cellZone SubSimulationDomain_Insulator ...
Found matching zone SubSimulationDomain_Insulator with 8618 cells.
Setting internal values of volScalarField epsilon

End

If I run the solver (myelectrostaticFoam), the solver crashes almost at the same time/way as before changing the standard solver electrostaticFoam:

/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev-debug |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : dev-debug-17954fc1734a
Exec : myelectrostaticFoam
Date : Dec 05 2017
Time : 06:25:27
Host : "SloOo7"
PID : 14265
I/O : uncollated
Case : /home/salehabuhanieh/OpenFOAM/salehabuhanieh-dev-debug/run/Case2Run_multiRegion
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading physicalProperties

Reading field epsilon

Reading field phi

Reading field rho

Calculating field rhoFlux


Starting iteration loop

Iteration = 5e-05

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.192831, No Iterations 1
smoothSolver: Solving for rho, Initial residual = 1, Final residual = 1.25419e-11, No Iterations 1
ExecutionTime = 2.41 s ClockTime = 3 s

Iteration = 0.0001

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21734e-12, Final residual = 4.21734e-12, No Iterations 0
ExecutionTime = 2.8 s ClockTime = 3 s

Iteration = 0.00015

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21733e-12, Final residual = 4.21733e-12, No Iterations 0
ExecutionTime = 3.2 s ClockTime = 3 s

Iteration = 0.0002

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21733e-12, Final residual = 4.21733e-12, No Iterations 0
ExecutionTime = 3.6 s ClockTime = 4 s

Iteration = 0.00025

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21733e-12, Final residual = 4.21733e-12, No Iterations 0
ExecutionTime = 3.99 s ClockTime = 4 s

Iteration = 0.0003

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21733e-12, Final residual = 4.21733e-12, No Iterations 0
ExecutionTime = 4.39 s ClockTime = 5 s

Iteration = 0.00035

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21733e-12, Final residual = 4.21733e-12, No Iterations 0
ExecutionTime = 4.79 s ClockTime = 5 s

Iteration = 0.0004

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21733e-12, Final residual = 4.21733e-12, No Iterations 0
ExecutionTime = 5.18 s ClockTime = 5 s

Iteration = 0.00045

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21733e-12, Final residual = 4.21733e-12, No Iterations 0
ExecutionTime = 5.58 s ClockTime = 6 s

Iteration = 0.0005

DICPCG: Solving for phi, Initial residual = 1, Final residual = 0.121097, No Iterations 2
smoothSolver: Solving for rho, Initial residual = 4.21733e-12, Final residual = 4.21733e-12, No Iterations 0
ExecutionTime = 5.97 s ClockTime = 6 s

Iteration = 0.00055

#0 Foam::error:rintStack(Foam::Ostream&) at /opt/OpenFOAM-dev-debug/src/OSspecific/POSIX/printStack.C:218
#1 Foam::sigFpe::sigHandler(int) at /opt/OpenFOAM-dev-debug/src/OSspecific/POSIX/signals/sigFpe.C:106
#2 ? in "/lib/x86_64-linux-gnu/libc.so.6"
#3 double Foam::sumProd<double>(Foam::UList<double> const&, Foam::UList<double> const&) at /opt/OpenFOAM-dev-debug/src/OpenFOAM/fields/Fields/scalarField/scalarField.C:98 (discriminator 2)
#4 double Foam::gSumProd<double>(Foam::UList<double> const&, Foam::UList<double> const&, int) at /opt/OpenFOAM-dev-debug/src/OpenFOAM/lnInclude/FieldFunctions.C:560
#5 Foam::PCG::solve(Foam::Field<double>&, Foam::Field<double> const&, unsigned char) const at /opt/OpenFOAM-dev-debug/src/OpenFOAM/matrices/lduMatrix/solvers/PCG/PCG.C:138 (discriminator 1)
#6 Foam::fvMatrix<double>::solveSegregated(Foam::dict ionary const&) at /opt/OpenFOAM-dev-debug/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.C:169 (discriminator 1)
#7 Foam::fvMatrix<double>::solve(Foam::dictionary const&) in "/opt/OpenFOAM-dev-debug/platforms/linux64GccDPInt32Debug/bin/myelectrostaticFoam"
#8 Foam::fvMatrix<double>::solve() in "/opt/OpenFOAM-dev-debug/platforms/linux64GccDPInt32Debug/bin/myelectrostaticFoam"
#9 Foam::SolverPerformance<double> Foam::solve<double>(Foam::tmp<Foam::fvMatrix<doubl e> > const&) in "/opt/OpenFOAM-dev-debug/platforms/linux64GccDPInt32Debug/bin/myelectrostaticFoam"
#10 ? in "/opt/OpenFOAM-dev-debug/platforms/linux64GccDPInt32Debug/bin/myelectrostaticFoam"
#11 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#12 ? in "/opt/OpenFOAM-dev-debug/platforms/linux64GccDPInt32Debug/bin/myelectrostaticFoam"
Floating point exception (core dumped)


you can see bellow myelectrostatic.C


#include "fvCFD.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
#include "setRootCase.H"

#include "createTime.H"
#include "createMesh.H"
#include "createFields.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Info<< "\nStarting iteration loop\n" << endl;

while (runTime.loop())
{
Info<< "Iteration = " << runTime.timeName() << nl << endl;

solve
(
fvm::laplacian(phi) + rho/epsilon
);

rhoFlux = -k*mesh.magSf()*fvc::snGrad(phi);

solve
(
fvm::ddt(rho) + fvm::div(rhoFlux, rho)
);

runTime.write();

Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
}

Info<< "End\n" << endl;

return 0;
}


// ************************************************** *********************** //



any ideas?

Saleh Abuhanieh is offline   Reply With Quote

Old   April 19, 2022, 08:31
Default
  #6
New Member
 
Zeinab Abosedaira
Join Date: Mar 2022
Posts: 24
Rep Power: 4
ZeinabM is on a distinguished road
Hello,
Since I am trying to use setfields for the same usage as you have here. I'd like to ask about how did you implement the use of setFields exactly. Now you have epsilon, and you're defining it in the physical properties files, but you're also defining it as a Field that has a file in the 0 folder. I don't get exactly how did you manage to implement it. Thank you!
ZeinabM is offline   Reply With Quote

Old   April 19, 2022, 09:37
Default
  #7
Member
 
Saleh Abuhanieh
Join Date: Nov 2017
Posts: 82
Rep Power: 8
Saleh Abuhanieh is on a distinguished road
Hi Zeinab,


It was an old post indeed!


I am not sure what you are trying to do. However, the idea behind the setFields utility is to set a non-uniform values for any fields before starting the simulation.


In the epsilon example, I wanted to set the field values for epsilon (which was used by the solver) differently according to the used material.


The user guide explains the usage of this utility well. Please have a look.



Regards,
Saleh
Saleh Abuhanieh is offline   Reply With Quote

Reply


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
Setting the height of the stream in the free channel kevinmccartin CFX 12 October 13, 2022 21:43
mass flow in is not equal to mass flow out saii CFX 12 March 19, 2018 05:21
Ansys CFX problem: unexpected very high temperatures in premix laminar combustion faizan_habib7 CFX 4 February 1, 2016 17:00
error message cuteapathy CFX 14 March 20, 2012 06:45
Two-Phase Buoyant Flow Issue Miguel Baritto CFX 4 August 31, 2006 12:02


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