Esempio n. 1
0
Foam::autoPtr<Foam::laminarModel<BasicTurbulenceModel>>
Foam::laminarModel<BasicTurbulenceModel>::New
(
    const alphaField& alpha,
    const rhoField& rho,
    const volVectorField& U,
    const surfaceScalarField& alphaRhoPhi,
    const surfaceScalarField& phi,
    const transportModel& transport,
    const word& propertiesName
)
{
    IOdictionary modelDict
    (
        IOobject
        (
            IOobject::groupName(propertiesName, U.group()),
            U.time().constant(),
            U.db(),
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE,
            false
        )
    );

    if (modelDict.found("laminar"))
    {
        // get model name, but do not register the dictionary
        // otherwise it is registered in the database twice
        const word modelType
        (
            modelDict.subDict("laminar").lookup("laminarModel")
        );

        Info<< "Selecting laminar stress model " << modelType << endl;

        typename dictionaryConstructorTable::iterator cstrIter =
            dictionaryConstructorTablePtr_->find(modelType);

        if (cstrIter == dictionaryConstructorTablePtr_->end())
        {
            FatalErrorInFunction
                << "Unknown laminarModel type "
                << modelType << nl << nl
                << "Valid laminarModel types:" << endl
                << dictionaryConstructorTablePtr_->sortedToc()
                << exit(FatalError);
        }

        return autoPtr<laminarModel>
        (
            cstrIter()
            (
                alpha,
                rho,
                U,
                alphaRhoPhi,
                phi,
                transport, propertiesName)
        );
    }
    else
    {
        Info<< "Selecting laminar stress model "
            << laminarModels::Stokes<BasicTurbulenceModel>::typeName << endl;

        return autoPtr<laminarModel>
        (
            new laminarModels::Stokes<BasicTurbulenceModel>
            (
                alpha,
                rho,
                U,
                alphaRhoPhi,
                phi,
                transport,
                propertiesName
            )
        );
    }
}
Esempio n. 2
0
int main(int argc, char *argv[])
{

#   include "setRootCase.H"

#   include "createTime.H"

    Info << "\nReading g" << endl;
    uniformDimensionedVectorField g
    (
        IOobject
        (
            "g",
            runTime.constant(),
            runTime,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );

    Info << "\nReading waveProperties\n" << endl;

    IOdictionary waveProperties
    (
        IOobject
        (
            "waveProperties.input",
            runTime.constant(),
            runTime,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );

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

    IOobject wOut
    (
            "waveProperties",
            runTime.constant(),
            runTime,
            IOobject::NO_READ,
            IOobject::NO_WRITE
    );

    // Write waveProperties with the above computed changes
    OFstream os
    (
        wOut.objectPath(),
#if EXTBRANCH==1
        ios_base::out|ios_base::trunc,
#elif OFPLUSBRANCH==1
        // Nothing to be put here
#else
    #if OFVERSION<170
        ios_base::out|ios_base::trunc,
    #endif
#endif
        IOstream::ASCII,
        IOstream::currentVersion,
        IOstream::UNCOMPRESSED
    );

    // Write the OF banner
    wOut.writeBanner( os );

    // Write the file information. Class name is not correct when
    // using wOut.writeHeader( os ); hence manual entries
    os << "FoamFile" << nl;
    os << token::BEGIN_BLOCK << incrIndent << nl;
    os << indent << "version" << tab << IOstream::currentVersion
       << token::END_STATEMENT << nl;
    os << indent << "format" << tab << "ascii;" << nl;
    os << indent << "class" << tab << "dictionary;" << nl;
    os << indent << "object" << tab << "waveProperties;" << nl;
    os << decrIndent << indent << token::END_BLOCK << nl;

    // Write the divider
    wOut.writeDivider( os );
    os << nl;

    /* Loop over all subdicts in waveProperties. For each of them compute the
       wave parameters relevant for that particular wave theory. */
    wordList toc = waveProperties.toc();

    forAll (toc, item)
    {
        // If a sub-dictionary, then compute parameters and write the subdict
        if (waveProperties.isDict(toc[item]))
        {
            dictionary& sd = waveProperties.subDict(toc[item]);

            autoPtr<setWaveProperties> props
                (
                    setWaveProperties::New(runTime, sd, true)
                );

            props->set( os );
        }
        else
        {
            label Nspaces = 20;

            // Read the entry and write to the dummy output file
            ITstream read = waveProperties.lookup(toc[item]);
            os << toc[item] << token::SPACE;

            for (int i=toc[item].size(); i<Nspaces-1; i++)
            {
                os << token::SPACE;
            }

            forAll (read, ri)
            {
                if (ri < read.size() - 1)
                {
                    os << read[ri] << token::SPACE;
                }
                else
                {
                    os << read[ri];
                }
            }

            os << token::END_STATEMENT << nl << endl;

            // Additional level of check, such that the code does not crash at
            // runTime:
            if (toc[item] == "seaLevel")
            {
            	// Read the magnitude of the sea level
            	scalar sL = readScalar(waveProperties.lookup("seaLevel"));

            	// If the Switch seaLevelAsReference is not found _and_ the
            	// magnitude of the sea level differs from 0 (zero), stop the
            	// evaluation of the wave parameters
            	if
            	(
            	    !waveProperties.found("seaLevelAsReference") &&
            	    SMALL < Foam::mag(sL)
            	)
            	{
            		// This merely looks up the string, it will not be found
            		// and the user is forced to correct waveProperties.input,
            		// before any execution is possible.
            		waveProperties.lookup("seaLevelAsReference");
            	}
            }
        }
    }

    // Write end divider
    wOut.writeEndDivider(os);

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

    return 0;
}
int main(int argc, char *argv[])
{
	bool allow_userdefined_fields = false;
	
	argList::noParallel();
	
	argList::validOptions.insert("rho", "value");
	argList::validOptions.insert("allowuserdefinedfields", "");
#if defined EXPORT_CYCLIC_BOUNDARIES	
	argList::validOptions.insert("exportcyclics", "");
#endif	
        //	argList::validOptions.insert("help", "");
#if 0	
	const word fieldTypes[] =
	{
		volScalarField::typeName,
		volVectorField::typeName
	};
#endif

#   include "addTimeOptions.H"
#   include "setRootCase.H"

	if(args.options().found("help"))
	{
		args.printUsage();
		exit(0);
	}
#if defined EXPORT_CYCLIC_BOUNDARIES	
	bool exportcyclics = false;
	if(args.options().found("exportcyclics"))
	{
		exportcyclics=true;
	}
#endif

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

	// Dictionnary for foamToCGNS options
#if 0	
	IOdictionary optionsDict
	(
		IOobject( "foamToCGNSDict", 
			  mesh.time().constant(), 
			  mesh,
			  IOobject::READ_IF_PRESENT, 
			  IOobject::NO_WRITE )
	);
	if ( optionsDict.headerOk() )
	{
		if ( optionsDict.found("SplitMixedCellTypes") )
			Info << "Options: Splitting multiple cell into different zones" << endl;
		if ( optionsDict.found("WriteConvergenceHistory") )
			Info << "Options: Writing convergence history found in 'log' file" << endl;
		if ( optionsDict.found("ConversionPath") )
		{
			const entry& e = optionsDict.lookupEntry( "ConversionPath" );
			Info << "Options: Conversion Path is " << e << endl;
		}
	}
#else
	foamToCGNSDictionary optionsDict
	(
		IOobject( "foamToCGNSDict", 
			  mesh.time().constant(), 
			  mesh,
			  IOobject::READ_IF_PRESENT, 
			  IOobject::NO_WRITE )
	);
	if ( optionsDict.headerOk() )
	{
		Info << "foamToCGNSOptions: " << endl;
		Info << "\tSplitting multiple cell into different zones : " << optionsDict.splitMixed() << endl;
		Info << "\tWriting convergence history found in 'log' file : " << optionsDict.writeConvergenceHistory() << endl;
		Info << "\tConversion Path is " << optionsDict.conversionDirectory() << endl;
		Info << "\tAllow User Defined Fields is " << optionsDict.allowUserDefinedFields() << endl;
	}
#endif
	
	if (args.options().found("allowuserdefinedfields") || optionsDict.allowUserDefinedFields() )
	{
		allow_userdefined_fields = true;
		Info << "User defined fields are allowed" << endl;
	}
	
	// Construct interpolation on the raw mesh
	volPointInterpolation pInterp(mesh);
	
	fileName cgnsDataPath(runTime.path()/"ConversionCGNS");
	mkDir(cgnsDataPath);
	
	// Get times list
	instantList Times = runTime.times();
	
	// set startTime and endTime depending on -time and -latestTime options
#   include "checkTimeOptions.H"

	// Get a value for the density 'rho' for purpose pour la mise a l'echelle du champs de pression
	//
	// First default value: 1.0
	//
	// Then, we check if rho is specified in the dictionary turboMathDict; if it is, we override the default value
	//
	// Finally, we allow the user to override the value of rho if the option -rho is provided on the commande line
	// or if the dictionnary is not present for this specific case.

	scalar rho_ = 1.0;  // Default value;
	Info << "Default value for rho: " << rho_ << endl;

#if 0	
	// Next we check for the dictionnary turboMathDict
	IOdictionary turboMathDict(
		IOobject
		(
			"turboMathDict",
			mesh.time().constant(),
			mesh, 
			IOobject::READ_IF_PRESENT,
			IOobject::NO_WRITE
		)
	);

	if(turboMathDict.headerOk())
	{
		dimensionedScalar dimensionedRho(turboMathDict.lookup("rho"));

		// Read the density value from the turboDictionnary
		rho_ = dimensionedRho.value();

		Info << "\nDictionary turboMathDict: new rho value : " << rho_ << endl;
	}
	else
	{
		Info << "Warning : no Dictionary turboMathDict" << endl;
	}
#endif
	// Finally, we allow this ultimate override from the command line
	if(args.options().found("rho"))
	{
		rho_ = readScalar(IStringStream(args.options()["rho"])());
		Info << "\nUser specified value for rho: new rho value : " << rho_ << endl;
	}
	Info << endl;
	
	// What kind of simulation is this?
	bool steadyState = false;

#if defined CGNSTOFOAM_EXTRACT_FlowEquationSet
	word application( runTime.controlDict().lookup( "application" ) );
	if ( application=="simpleFoam" )
	{
		Info << "Solution computed with simpleFoam" << endl;
		word default_ddtScheme = mesh.ddtScheme("default");
		Info << "\tddtScheme = " << default_ddtScheme << endl;
		steadyState = ( default_ddtScheme == "steadyState" );
		
		// what is the turbulence model ?

#include "incompressible/simpleFoam/createFields.H"
	}
	else if ( application=="icoFoam" )
	{
		Info << "Solution computed with icoFoam" << endl;
	}
	else
	{
		Info << "Warning : unknown application : " << application << endl;
		Info << "Warning : will not include FlowEquationSet in the CGNS file" << endl;
	}
#endif //CGNSTOFOAM_EXTRACT_FlowEquationSet

	
#if 1
	std::string logfilename = args.caseName() + "/log";
	std::ifstream ifslog( logfilename.c_str() );
	if ( !ifslog )
	{
		Info << "Warning : log file not found. No convergence history will be included." << endl;	
	}
	else
	{
		logFile logf( ifslog );
		int nsteps = logf.getNSteps();
		Info << nsteps << " Steps found in convergence history" << endl;
	}
#endif
	
#if 1
	for (label i=startTime; i<endTime; i++)
	{
		runTime.setTime(Times[i], i);
	
		mesh.readUpdate();
	
		IOobjectList objects(mesh, runTime.timeName());
	
		Info << "----> Timestep: " << Times[i].name() << endl;
	
#include "writeCGNS.H"    // write a CGNS file for this time step
	
		Info << endl;
	}

#endif

	Info << "Done" << endl;
	
	return 0;
}
int main(int argc, char *argv[])
{
    argList::noParallel();
    argList::addBoolOption("rewrite");
    argList::addBoolOption("show");

    argList args(argc, argv);

    Time runTime(args.rootPath(), args.caseName());

    const word dictName("fvSolution");

    bool optRewrite = args.optionFound("rewrite");
    bool optShow = args.optionFound("show");

    IOdictionary solutionDict
    (
        IOobject
        (
            dictName,
            "system",
            runTime,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE,
            false
        )
    );

    if (!solutionDict.found("solvers"))
    {
        Info<<"no solvers entry found in : " << dictName << endl;
        return 2;
    }

    if (optRewrite && solutionDict.instance() != "system")
    {
        Info<<"instance is not 'system' "
            "- disabling rewrite for this file" << nl;
        optRewrite = false;
    }

    dictionary& solverDict = solutionDict.subDict("solvers");

    wordList names = solverDict.toc();
    wordList oldNames = names;

    bool changed = false;
    for (label orig = 0; orig < names.size()-1; ++orig)
    {
        // skip patterns or entries that have already been done
        if (names[orig].empty() || wordRe::isPattern(names[orig]))
        {
            continue;
        }

        const dictionary& dict1 = solverDict.subDict(names[orig]);

        for (label check = orig+1; check < names.size(); ++check)
        {
            // skip patterns or entries that have already been done
            if (names[check].empty() || wordRe::isPattern(names[check]))
            {
                continue;
            }

            const dictionary& dict2 = solverDict.subDict(names[check]);

            // check for identical content
            if (checkDictionaryContent(dict1, dict2))
            {
                names[orig] += "|" + names[check];
                names[check].clear();
                changed = true;
            }
        }
    }

    if (changed)
    {
        forAll(names, nameI)
        {
            if (names[nameI].empty())
            {
                solverDict.remove(oldNames[nameI]);
                Info<<"  #remove " << oldNames[nameI];
            }
            else
            {
                Info<< "  " << oldNames[nameI];

                if (names[nameI] != oldNames[nameI])
                {
                    // make "(abc|def)" pattern
                    keyType renamed( "(" + names[nameI] + ")", true);

                    solverDict.changeKeyword(oldNames[nameI], renamed);

                    Info<< " -> " << renamed;
                }
            }
            Info<< endl;
        }

        if (optRewrite)
        {
            mvBak(solutionDict.objectPath(), "orig");
            Info<< "Backup to .orig" << nl
                << "Writing " << solutionDict.objectPath() << nl << endl;

            solutionDict.regIOobject::write();
        }
        else if (optShow)
        {
            IOobject::writeDivider(Info);
            solutionDict.dictionary::write(Info, false);
        }
        else
        {
            Info<< "\nFile not rewritten" << endl;
        }
    }
    else
    {