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/)
-   -   set directory for subMesh (https://www.cfd-online.com/Forums/openfoam-programming-development/113582-set-directory-submesh.html)

Fabian_W February 22, 2013 07:14

set directory for subMesh
 
I am stucked and need help.

I create my subMesh as

fvMeshSubset sm(mesh);
sm.setCellSubset(sub);

with the submesh I create volScalarField k_e and h_e

What I actually need is the laplacian matrix

fvMatrix<scalar> m = fvm::laplacian(k_e, h_2)

But sm.subMesh().schemesDict() is empty and has no laplacianSchemes.

I did not find how to add the schemes file:

keyword laplacian(k,h) is undefined in dictionary ".../system/region0SubSet/fvSchemes::laplacianSchemes"

And I was also not able to set i programatically as sm.subMesh().schemesDict() ist const.

How can I set my laplacian schemes for my subMesh?

ngj February 22, 2013 07:18

Hi Fabian

Merely make a folder called system/region0SubSet and create an fvSolution and fvScheme file in this directory. OpenFoam will automatically find these files and use them in a way identical to the basic fvSolution and fvScheme files.

Kind regards,

Niels

Fabian_W February 22, 2013 07:22

Thanks four your reply Niels.

It does not work. When I do sm.setLargeCellSubset(sub, -1, false) instead of sm.setCellSubset(sub); the name is not changed (also commented in fvMeshSubset.C) but the directory is also empty.

Do I miss something? Do I need to activate reading from the directory?

ngj February 22, 2013 08:05

Hi Fabian,

I went into my code to see my steps:

1. This is how I create the subMesh:
Code:

    // Creates a fvMeshSubset (Construction done differently in 1.6 and onwards)
    submesh_ = new fvMeshSubset(cGlobal_, mesh_);

    // Set the cell labels to be used in cMesh. (cellSet, label, bool)
    submesh_->setLargeCellSubset(suspendedCells, suspPatchID_, true);

    // Write cMesh - write all information!
    submesh_->subMesh().setInstance( mesh_.time().constant() );
    submesh_->subMesh().write();

    // Make sure that only the points are written to the disk
    submesh_->subMesh().setInstance( mesh_.time().timeName() );
    submesh_->subMesh().setTopoWriteOpt(IOobject::NO_WRITE);

2. I have the following method in my class:
Code:

inline const fvMesh & cMesh() const
{
    return submesh_->subMesh();
};

3. Volume fields are subsequently created in the following way, and when I perform fvc:: and fvm:: on these, it works as a charm:

Code:

volScalarField k
(
    IOobject
    (
        "k",
        mesh_.time().timeName(),
        cMesh(),
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    cMesh()
);

Good luck,

Niels

ngj February 22, 2013 08:28

P.S. This works in 1.6-ext.

/ Niels

Fabian_W February 22, 2013 10:21

I have 2.1.1, this might be the problem. The files exist, but as my dictionary is empty it might be the case that it is not read :(

I found that the vectors are only properly read when their name in their header are ok. I tried to play a little bit with the location.

How can I activate debug output? I have problems debugging my code, one day it works (complete OpenFoam build in debug version) the other day it does not work with gdb :( (Linux)

ngj February 22, 2013 15:12

Well, if the files do exist, then what happens if you define how to compute the Laplacian? As I understand it, you have not defined the discretisation in system/region0SubSet/fvSchemes?

I have no experience with GDB, thus I cannot help you in that regard.

Have a nice weekend,

Niels

Fabian_W February 25, 2013 05:14

Quote:

Originally Posted by ngj (Post 409590)
Well, if the files do exist, then what happens if you define how to compute the Laplacian? As I understand it, you have not defined the discretisation in system/region0SubSet/fvSchemes?

I have no experience with GDB, thus I cannot help you in that regard.

The file exists, I copied fvSchemes and fvSolutions from system to system/region0SubSet

I tried also with adding region0SubSet to location or object in these files.

sm.subMesh().schemesDict().size() is always empty.

Any more hints? It might be something stupid, e.g. like setting the wrong entries in the location field in the files or some other file needs to be present in region0SubSet, ...?

Fabian_W February 27, 2013 03:47

The submesh definetly does not try to read the scheme. I checked with strace the system calls and see all file operations.

I also cannot call

dynamic_cast<fvSchemes&>(sm.subMesh()).read()

as the readOpt is set to READ_ONLY and I did not find, who it can be changed.

Meanwhile I'm sure this is a bug in OpenFOAM 2.1.1

This is the laplacian method in question:

laplacian
(
const GeometricField<GType, fvPatchField, volMesh>& gamma,
const GeometricField<Type, fvPatchField, volMesh>& vf,
const word& name
)
{
return fv::laplacianScheme<Type, GType>::New
(
vf.mesh(),
vf.mesh().laplacianScheme(name)
)().fvmLaplacian(gamma, vf);
}

I add a own implementation where I can provide the laplacianScheme of the system mesh

laplacian
(
const GeometricField<GType, fvPatchField, volMesh>& gamma,
const GeometricField<Type, fvPatchField, volMesh>& vf,
const word& name,
ITstream& scheme
)
{
return fv::laplacianScheme<Type, GType>::New
(
vf.mesh(),
scheme
)().fvmLaplacian(gamma, vf);
}

ngj February 27, 2013 03:49

Hi Fabian,

It is good that you found a work-around. Please report the issue in the OpenCFD's bug-tracker.

Kind regards

Niels

Jacks April 24, 2014 09:28

Other solution
 
As fvMesh Objects are indeed construct with the NO_READ IOObject option, it do not read fvSchemes nor fvSolution dict neither for subMesh constructed from setCellSubSet() method (and looking for a system/region0SubSet as instance dir.) nor for setLargeCellSubSet(), which keeps the parent mesh system directory.

A solution, which seems to work, is to set the subMesh read option on MUST_READ manually via:

Code:

subMesh.fvSchemes::readOpt() = parentMesh.fvSchemes::readOpt();
 subMesh.fvSolution::readOpt() = parentMesh.fvSolution::readOpt();

And ask it for red these dictionnary:

Code:

subMesh.fvSchemes::read();
 subMesh.fvSolution::read();

I keep testing this solution but it seems to work for me.

Best regards,


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