void Foam::fv::CodedSource<Type>::prepare
(
    dynamicCode& dynCode,
    const dynamicCodeContext& context
) const
{
    word sourceType(pTraits<Type>::typeName);

    // Set additional rewrite rules
    dynCode.setFilterVariable("typeName", name_);
    dynCode.setFilterVariable("TemplateType", sourceType);
    dynCode.setFilterVariable("SourceType", sourceType + "Source");

    //dynCode.removeFilterVariable("code");
    dynCode.setFilterVariable("codeCorrect", codeCorrect_);
    dynCode.setFilterVariable("codeAddSup", codeAddSup_);
    dynCode.setFilterVariable("codeSetValue", codeSetValue_);

    // compile filtered C template
    dynCode.addCompileFile("codedFvOptionTemplate.C");

    // copy filtered H template
    dynCode.addCopyFile("codedFvOptionTemplate.H");

    // debugging: make BC verbose
    //         dynCode.setFilterVariable("verbose", "true");
    //         Info<<"compile " << name_ << " sha1: "
    //             << context.sha1() << endl;

    // define Make/options
    dynCode.setMakeOptions
        (
            "EXE_INC = -g \\\n"
            "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
            "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
            "-I$(LIB_SRC)/sampling/lnInclude \\\n"
            "-I$(LIB_SRC)/fvOptions/lnInclude \\\n"
            + context.options()
            + "\n\nLIB_LIBS = \\\n"
            + "    -lmeshTools \\\n"
            + "    -lfvOptions \\\n"
            + "    -lsampling \\\n"
            + "    -lfiniteVolume \\\n"
            + context.libs()
        );
}
void Foam::codedFunctionObject::prepare
(
    dynamicCode& dynCode,
    const dynamicCodeContext& context
) const
{
    // Set additional rewrite rules
    dynCode.setFilterVariable("typeName", redirectType_);
    dynCode.setFilterVariable("codeRead", codeRead_);
    dynCode.setFilterVariable("codeExecute", codeExecute_);
    dynCode.setFilterVariable("codeEnd", codeEnd_);
    dynCode.setFilterVariable("codeData", codeData_);
    dynCode.setFilterVariable("codeTimeSet", codeTimeSet_);
    //dynCode.setFilterVariable("codeWrite", codeWrite_);

    // compile filtered C template
    dynCode.addCompileFile("functionObjectTemplate.C");
    dynCode.addCompileFile("FilterFunctionObjectTemplate.C");

    // copy filtered H template
    dynCode.addCopyFile("FilterFunctionObjectTemplate.H");
    dynCode.addCopyFile("functionObjectTemplate.H");
    dynCode.addCopyFile("IOfunctionObjectTemplate.H");

    // debugging: make BC verbose
    //         dynCode.setFilterVariable("verbose", "true");
    //         Info<<"compile " << redirectType_ << " sha1: "
    //             << context.sha1() << endl;

    // define Make/options
    dynCode.setMakeOptions
        (
            "EXE_INC = -g \\\n"
            "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
            "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
            + context.options()
            + "\n\nLIB_LIBS = \\\n"
            + "    -lOpenFOAM \\\n"
            + "    -lfiniteVolume \\\n"
            + "    -lmeshTools \\\n"
            + context.libs()
        );
}
void Foam::codedFixedValueFvPatchField<Type>::prepare
(
    dynamicCode& dynCode,
    const dynamicCodeContext& context
) const
{
    // take no chances - typeName must be identical to redirectType_
    dynCode.setFilterVariable("typeName", redirectType_);

    // set TemplateType and FieldType filter variables
    // (for fvPatchField)
    setFieldTemplates(dynCode);

    // compile filtered C template
    dynCode.addCompileFile(codeTemplateC);

    // copy filtered H template
    dynCode.addCopyFile(codeTemplateH);


    // debugging: make BC verbose
    //  dynCode.setFilterVariable("verbose", "true");
    //  Info<<"compile " << redirectType_ << " sha1: "
    //      << context.sha1() << endl;

    // define Make/options
    dynCode.setMakeOptions
        (
            "EXE_INC = -g \\\n"
            "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
            + context.options()
            + "\n\nLIB_LIBS = \\\n"
            + "    -lOpenFOAM \\\n"
            + "    -lfiniteVolume \\\n"
            + context.libs()
        );
}
示例#4
0
void Foam::codedFunctionObject::createLibrary
(
    dynamicCode& dynCode,
    const dynamicCodeContext& context
) const
{
    bool create = Pstream::master();

    if (create)
    {
        // Write files for new library
        if (!dynCode.upToDate(context))
        {
            // filter with this context
            dynCode.reset(context);

            // Set additional rewrite rules
            dynCode.setFilterVariable("typeName", redirectType_);
            dynCode.setFilterVariable("codeRead", codeRead_);
            dynCode.setFilterVariable("codeExecute", codeExecute_);
            dynCode.setFilterVariable("codeEnd", codeEnd_);
            //dynCode.setFilterVariable("codeWrite", codeWrite_);

            // compile filtered C template
            dynCode.addCompileFile("functionObjectTemplate.C");
            dynCode.addCompileFile("FilterFunctionObjectTemplate.C");

            // copy filtered H template
            dynCode.addCopyFile("FilterFunctionObjectTemplate.H");
            dynCode.addCopyFile("functionObjectTemplate.H");
            dynCode.addCopyFile("IOfunctionObjectTemplate.H");

            // debugging: make BC verbose
            //         dynCode.setFilterVariable("verbose", "true");
            //         Info<<"compile " << redirectType_ << " sha1: "
            //             << context.sha1() << endl;

            // define Make/options
            dynCode.setMakeOptions
            (
                "EXE_INC = -g \\\n"
                "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
              + context.options()
              + "\n\nLIB_LIBS = \\\n"
              + "    -lOpenFOAM \\\n"
              + "    -lfiniteVolume \\\n"
              + context.libs()
            );

            if (!dynCode.copyOrCreateFiles(true))
            {
                FatalIOErrorIn
                (
                    "codedFunctionObject::createLibrary(..)",
                    context.dict()
                )   << "Failed writing files for" << nl
                    << dynCode.libRelPath() << nl
                    << exit(FatalIOError);
            }
        }

        if (!dynCode.wmakeLibso())
        {
            FatalIOErrorIn
            (
                "codedFunctionObject::createLibrary(..)",
                context.dict()
            )   << "Failed wmake " << dynCode.libRelPath() << nl
                << exit(FatalIOError);
        }
    }


    // all processes must wait for compile to finish
    reduce(create, orOp<bool>());
}
示例#5
0
void Foam::codedBase::createLibrary
(
    dynamicCode& dynCode,
    const dynamicCodeContext& context
) const
{
    bool create =
        Pstream::master()
     || (regIOobject::fileModificationSkew <= 0);   // not NFS

    if (create)
    {
        // Write files for new library
        if (!dynCode.upToDate(context))
        {
            // filter with this context
            dynCode.reset(context);

            this->prepare(dynCode, context);

            if (!dynCode.copyOrCreateFiles(true))
            {
                FatalIOErrorInFunction
                (
                    context.dict()
                )   << "Failed writing files for" << nl
                    << dynCode.libRelPath() << nl
                    << exit(FatalIOError);
            }
        }

        if (!dynCode.wmakeLibso())
        {
            FatalIOErrorInFunction
            (
                context.dict()
            )   << "Failed wmake " << dynCode.libRelPath() << nl
                << exit(FatalIOError);
        }
    }


    // all processes must wait for compile to finish
    if (regIOobject::fileModificationSkew > 0)
    {
        //- Since the library has only been compiled on the master the
        //  other nodes need to pick this library up through NFS
        //  We do this by just polling a few times using the
        //  fileModificationSkew.

        const fileName libPath = dynCode.libPath();

        off_t mySize = Foam::fileSize(libPath);
        off_t masterSize = mySize;
        Pstream::scatter(masterSize);

        if (debug)
        {
            Pout<< endl<< "on processor " << Pstream::myProcNo()
                << " have masterSize:" << masterSize
                << " and localSize:" << mySize
                << endl;
        }


        if (mySize < masterSize)
        {
            if (debug)
            {
                Pout<< "Local file " << libPath
                    << " not of same size (" << mySize
                    << ") as master ("
                    << masterSize << "). Waiting for "
                    << regIOobject::fileModificationSkew
                    << " seconds." << endl;
            }
            Foam::sleep(regIOobject::fileModificationSkew);

            // Recheck local size
            mySize = Foam::fileSize(libPath);

            if (mySize < masterSize)
            {
                FatalIOErrorInFunction
                (
                    context.dict()
                )   << "Cannot read (NFS mounted) library " << nl
                    << libPath << nl
                    << "on processor " << Pstream::myProcNo()
                    << " detected size " << mySize
                    << " whereas master size is " << masterSize
                    << " bytes." << nl
                    << "If your case is not NFS mounted"
                    << " (so distributed) set fileModificationSkew"
                    << " to 0"
                    << exit(FatalIOError);
            }
        }

        if (debug)
        {
            Pout<< endl<< "on processor " << Pstream::myProcNo()
                << " after waiting: have masterSize:" << masterSize
                << " and localSize:" << mySize
                << endl;
        }
    }
    reduce(create, orOp<bool>());
}
void Foam::codedFixedValueFvPatchField<Type>::createLibrary
(
    dynamicCode& dynCode,
    const dynamicCodeContext& context
) const
{
    bool create = Pstream::master();

    if (create)
    {
        // Write files for new library
        if (!dynCode.upToDate(context))
        {
            // filter with this context
            dynCode.reset(context);

            // take no chances - typeName must be identical to redirectType_
            dynCode.setFilterVariable("typeName", redirectType_);

            // set TemplateType and FieldType filter variables
            // (for fvPatchField)
            setFieldTemplates(dynCode);

            // compile filtered C template
            dynCode.addCompileFile(codeTemplateC);

            // copy filtered H template
            dynCode.addCopyFile(codeTemplateH);


            // debugging: make BC verbose
            //  dynCode.setFilterVariable("verbose", "true");
            //  Info<<"compile " << redirectType_ << " sha1: "
            //      << context.sha1() << endl;

            // define Make/options
            dynCode.setMakeOptions
            (
                "EXE_INC = -g \\\n"
                "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
              + context.options()
              + "\n\nLIB_LIBS = \\\n"
              + "    -lOpenFOAM \\\n"
              + "    -lfiniteVolume \\\n"
              + context.libs()
            );

            if (!dynCode.copyOrCreateFiles(true))
            {
                FatalIOErrorIn
                (
                    "codedFixedValueFvPatchField<Type>::createLibrary(..)",
                    context.dict()
                )   << "Failed writing files for" << nl
                    << dynCode.libRelPath() << nl
                    << exit(FatalIOError);
            }
        }

        if (!dynCode.wmakeLibso())
        {
            FatalIOErrorIn
            (
                "codedFixedValueFvPatchField<Type>::createLibrary(..)",
                context.dict()
            )   << "Failed wmake " << dynCode.libRelPath() << nl
                << exit(FatalIOError);
        }
    }


    // all processes must wait for compile to finish
    reduce(create, orOp<bool>());
}