CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   using boxes to partition constant-regions for computing (https://www.cfd-online.com/Forums/openfoam-programming-development/161898-using-boxes-partition-constant-regions-computing.html)

cfdopenfoam October 31, 2015 03:27

using boxes to partition constant-regions for computing
 
dear foamers,

i will be very sorry if the title misleads you. well, i am trying to partition my computational domain (not mesh or grid) into several "subregions", and each "subregion" has two constant factors for some computation. different "subregions" will have different constant factors. i hope you know that this is not for parallel computing and i do not mean to decompose any fields or mesh. what i want to do is to impose specific constants to corresponding "subregions" and i consider this as some pre-processing. the very simple psudo-code may be as follows:
Code:

// this file locates in constant/ and named by subregionProperties
constantFactors1 4 // lets say, 4 subregions
(
    subregionName0    0.1;
    subregionName1    0.2;
    subregionName2    0.1;
    subregionName3    0.3;
);

constantFactors2 4 // lets say, 4 subregions
(
    subregionName0    0.3;
    subregionName1    0.1;
    subregionName2    0.2;
    subregionName3    0.5;
)

during simulation, I want to use these factors:
Code:

// during runTime
    if(current cell in subregionName0) then use factors(0.1 0.3);
// or if(current cell in box0) then use factors(0.1 0.3);
    ...

I do not want every cell to have 2 fields to store the factors but cells in subregions to share the corresponding factors. I guess firstly I may need use box to define the "subregions" locations and the following :confused:??? how should i make the implementation???
i hope i have clarified my intention. thanks for your attention.

wyldckat October 31, 2015 09:41

Quick answer: http://www.cfd-online.com/Forums/ope...tml#post512233 - post #10

cfdopenfoam November 1, 2015 06:52

Quote:

Originally Posted by wyldckat (Post 571151)

thanks for your help. i have been struggling on this problem these days and i learned how to basically use topoSet and setSet, probably as some pre-processing. but my intention is to do something with the sets (or maybe zones) during runtime. (BTW, why we have mesh.cellZone() but not mesh.cellSet() :confused:)
also, i draft the pesudo-code in mySolver.C:
Code:

// the following code to be added in mySolver.C
List<dimensionedScalar> p1(subregionPropertiesDict.lookup("constantFactors1"));
forAll(p1, i)
{
    const word regionName = p1[i].name();
    forAll(cellsInRegionName, cellI)
    {
        U[cellI] = U[cellI] * p1[i].value();
    };
};

i am sorry that i am new to openfoam coding and please help me correct my mistakes. thanks in advance.
/karelke

wyldckat November 1, 2015 15:55

Hi Karelke,

Sorry, I should have emphasized this line from the post I mentioned:
Quote:

Originally Posted by wyldckat (Post 512233)

There you will find that setFields is used in a similar way to topoSet. You can use setFields for assigning a value to a field based on bounding boxes.
The 3rd tutorial on the OpenFOAM User Guide explains how to use setFields: http://cfd.direct/openfoam/user-guid...#x7-530002.3.3 - subsection "2.3.3 Setting initial field"

Quote:

Originally Posted by cfdopenfoam (Post 571266)
BTW, why we have mesh.cellZone() but not mesh.cellSet() http://www.cfd-online.com/Forums/ima...s/confused.gif

"cellSet" is what I like to call a shopping list. It has a list of cells index/identification numbers and only that.
"cellZone" is an actual zone in the mesh, that can be created from a "cellSet". A "cellZone" can have its own mesh characteristics, such as identification of what's inside and orientation and stuff like that (sorry, I can't remember all of the details right now).

As for the code you're trying to use... I believe that by using setFields to define the values for a specific field, for example one named "Zoning", you can then load the "Zoning" field file the same way that "U" and "p" are loaded in the solver's "createFields.H". Then you can use something like this:
Code:

// the following code to be added in mySolver.C
List<dimensionedScalar> p1(subregionPropertiesDict.lookup("constantFactors1"));
forAll(p1, i)
{
    const word regionName = p1[i].name();
    forAll(U, cellI)
    {
        if(p1[i].value() == Zoning[cellI])
        {
            U[cellI] = U[cellI] * p1[i].value();
        }
    };
};

Uh... not sure if this is what you really want to do, but the idea I want to give you is that the field "Zoning" is the one that will have the values that identify your region.

Best regards,
Bruno

cfdopenfoam November 1, 2015 22:21

Quote:

Originally Posted by wyldckat (Post 571332)
"cellSet" is what I like to call a shopping list. It has a list of cells index/identification numbers and only that.
"cellZone" is an actual zone in the mesh, that can be created from a "cellSet". A "cellZone" can have its own mesh characteristics, such as identification of what's inside and orientation and stuff like that (sorry, I can't remember all of the details right now).

thank you for so much type-in. i must apologize for making my problem difficult to understand. well, in fact i could do this as the method you offered. namely create a new volScalarField constantFactor and set this field with setFields. thus i could use it without particularly coding in mySolver.C because every cell possesses this field constantFactor. however, these occupy unnecessary memory and i wonder if i could let cells in certain sets or zones or subregions share a single scalar value during runTime but not only the initial time (as setFields do). and thus i think i need some particulary coding in mySolver.C and i am now struggling on how to do it.
maybe this intention could not be easy (or even possible) to implement. but that is what this thread posted to ask. hope that clarified.
thanks again for your attention.:)

chriss85 November 2, 2015 03:48

You might be able to do that if you compute some field values manually, e.g. not in a differential equation. However, in normal cases I would suggest using a field with the factors assigned as its values. Then you can directly use the field in an equation. The memory requirement is usually not the limiting factor in OpenFOAM.

cfdopenfoam November 2, 2015 04:15

Quote:

Originally Posted by chriss85 (Post 571380)
You might be able to do that if you compute some field values manually, e.g. not in a differential equation. However, in normal cases I would suggest using a field with the factors assigned as its values. Then you can directly use the field in an equation. The memory requirement is usually not the limiting factor in OpenFOAM.

greetings to chriss85.

yeah. what i need do is actually some simple manually-computing and it's not in a differential equation. and now i find it might indeed not be a easy task without creating a field. but i wonder if there are (or should be) classes such as cellSetScalarField or cellZoneScalarField for convenience.
at last i think the problem will be solved as what you and Bruno have suggested.
BTW, in terms of the dictionary
Code:

// this file locates in constant/ and named by subregionProperties
constantFactors1 4 // lets say, 4 subregions. is this a list?
(
    subregionName0    0.1;  // delimited by a ";"??
    subregionName1    0.2;
    subregionName2    0.1;
    subregionName3    0.3;
);

how should i read the dict and load the value?
thanks for your attention and valuable suggestion.:)


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