Skip to content

Commit

Permalink
Merge pull request #22 from kmokstad/namespace-ftk
Browse files Browse the repository at this point in the history
Some FFlLib refactoring
  • Loading branch information
kmokstad authored Jan 31, 2025
2 parents 6459233 + cd764b0 commit 271b9ff
Show file tree
Hide file tree
Showing 171 changed files with 4,086 additions and 3,687 deletions.
24 changes: 8 additions & 16 deletions pFUnit/pFUnit-3.3.3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@
#
# ------------------------------------------------------------------------ #
INCLUDE(CMakeForceCompiler)
cmake_minimum_required(VERSION 3.0...3.5)
cmake_minimum_required(VERSION 3.0...3.10)
cmake_policy(SET CMP0048 NEW)
project (pFUnit
VERSION 3.1.1
LANGUAGES Fortran)
#enable_language (Fortran)

# MESSAGE(ENV{PFUNIT}:"$ENV{PFUNIT}")
# set (ENV_PFUNIT "$ENV{PFUNIT}")
# MESSAGE(OK:"${ENV_PFUNIT}")
# OPTION(INSTALL_PATH "Use PFUNIT for development" "$ENV{PFUNIT}")
# OPTION(INSTALL_PATH "Use PFUNIT for development" "${ENV_PFUNIT}")
OPTION(INSTALL_PATH "Use PFUNIT for development" OFF)
project(pFUnit VERSION 3.1.1 LANGUAGES Fortran)

OPTION(INSTALL_PATH "Use PFUNIT for development" OFF)
IF(NOT INSTALL_PATH)
IF(DEFINED ENV{PFUNIT})
set (INSTALL_PATH "$ENV{PFUNIT}")
Expand Down Expand Up @@ -94,10 +86,10 @@ endif()
if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")

if (UNIX)
execute_process (COMMAND ifort --version
OUTPUT_VARIABLE INTEL_COMPILER_VERSION)
string (REGEX MATCH "([0-9]+)"
NUM_VERSION ${INTEL_COMPILER_VERSION})
execute_process (COMMAND ifort --version
OUTPUT_VARIABLE INTEL_COMPILER_VERSION)
string (REGEX MATCH "([0-9]+)"
NUM_VERSION ${INTEL_COMPILER_VERSION})
if ("${NUM_VERSION}" STREQUAL "13")
add_definitions(-DINTEL_13)
endif ()
Expand Down
16 changes: 7 additions & 9 deletions pFUnit/pFUnit-3.3.3/source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.8...3.5)
cmake_minimum_required(VERSION 2.8...3.10)

SET (CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod)

if (CMAKE_VERSION VERSION_LESS 3.12)
find_package(PythonInterp REQUIRED) #Sets ${PYTHON_EXECUTABLE}
Expand All @@ -27,8 +27,8 @@ execute_process(
OUTPUT_VARIABLE generated_sources_output
)

message( STATUS "Including generated file(s) '${generated_sources_output}'" )
include( ${CMAKE_CURRENT_BINARY_DIR}/${generated_sources_output} )
message(STATUS "Including generated file(s) '${generated_sources_output}'")
include(${CMAKE_CURRENT_BINARY_DIR}/${generated_sources_output})

list(APPEND srcs AssertBasic.F90)

Expand Down Expand Up @@ -87,12 +87,10 @@ list(APPEND pysrcs CodeUtilities.py)
list(APPEND pysrcs GenerateAssertsOnArrays.py)
list(APPEND pysrcs Utilities.py)

set(SOURCES ${srcs})

add_library(pfunit STATIC ${SOURCES})
add_library(pfunit STATIC ${srcs})

include_directories(${CMAKE_BINARY_DIR}/mod)
include_directories(${CMAKE_BINARY_DIR}/source)

INSTALL(TARGETS pfunit DESTINATION lib)
INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/mod DESTINATION .)
install(TARGETS pfunit DESTINATION lib)
install(DIRECTORY ${CMAKE_BINARY_DIR}/mod DESTINATION .)
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ message ( STATUS "INFORMATION : Processing unit ${UNIT_ID}" )

include_directories ( "${CMAKE_CURRENT_SOURCE_DIR}" )

if ( "${APPLICATION_ID}" STREQUAL "fedemKernel" )
string ( APPEND CMAKE_CXX_FLAGS " -DFF_NAMESPACE=FTK" )
endif ( "${APPLICATION_ID}" STREQUAL "fedemKernel" )

if ( USE_FORTRAN )
set ( CMAKE_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/f90_modules" )
endif ( USE_FORTRAN )
Expand Down
4 changes: 4 additions & 0 deletions src/FFlLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ if ( USE_VTFAPI )
find_package ( VTFAPI )
endif ( USE_VTFAPI )

if ( USE_REFCOUNT )
string ( APPEND CMAKE_CXX_FLAGS " -DFFL_REFCOUNT" )
endif ( USE_REFCOUNT )

if ( USE_PROFILER )
string ( APPEND CMAKE_CXX_FLAGS " -DFFL_TIMER" )
endif ( USE_PROFILER )
Expand Down
14 changes: 8 additions & 6 deletions src/FFlLib/FFlAttributeBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <iomanip>
#endif

#ifdef FF_NAMESPACE
namespace FF_NAMESPACE {
#endif


const std::string& FFlAttributeBase::getTypeName() const
{
Expand Down Expand Up @@ -56,16 +60,14 @@ bool FFlAttributeBase::isIdentic(const FFlAttributeBase* other) const
}


int FFlAttributeBase::getAttributeTypeID() const
{
return this->getFEAttributeSpec()->getAttributeTypeID(this->getTypeName());
}


void FFlAttributeBase::print(const char* prefix) const
{
std::cout << prefix << this->getTypeName()
<<", ID = "<< this->getID() <<", Fields:";
for (FFlFieldBase* field : myFields) std::cout <<" "<< *field;
std::cout << std::endl;
}

#ifdef FF_NAMESPACE
} // namespace
#endif
11 changes: 8 additions & 3 deletions src/FFlLib/FFlAttributeBase.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class FFlFieldBase;
class FFaCheckSum;
class FFaUnitCalculator;

#ifdef FF_NAMESPACE
namespace FF_NAMESPACE {
#endif


class FFlAttributeBase : public FFlNamedPartBase,
public FFlFEAttributeRefs
Expand Down Expand Up @@ -50,16 +54,14 @@ public:
virtual void resize(size_t n) { if (n < myFields.size()) myFields.resize(n); }

protected:
int getAttributeTypeID() const;

void addField(FFlFieldBase& field) { myFields.push_back(&field); }

private:
std::vector<FFlFieldBase*> myFields;
};


typedef FFaGenericFactory<FFlAttributeBase> AttributeFactory;
using AttributeFactory = FFaGenericFactory<FFlAttributeBase>;


#define FFL_FE_ATTRIBUTE_FACTORY_INIT(clName) \
Expand All @@ -70,4 +72,7 @@ public: \
virtual FFlAttributeBase* clone() const \
{ return new clName(*this); }

#ifdef FF_NAMESPACE
} // namespace
#endif
#endif
8 changes: 8 additions & 0 deletions src/FFlLib/FFlElementBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "FFaLib/FFaAlgebra/FFaTensor3.H"
#include "FFaLib/FFaAlgebra/FFaMat33.H"

#ifdef FF_NAMESPACE
namespace FF_NAMESPACE {
#endif


FFlElementBase::FFlElementBase(int id) : FFlPartBase(id)
{
Expand Down Expand Up @@ -124,3 +128,7 @@ bool FFlElementBase::invertMapping(const FaVec3&, double*) const
<< this->getTypeName() <<" elements."<< std::endl;
return false;
}

#ifdef FF_NAMESPACE
} // namespace
#endif
15 changes: 12 additions & 3 deletions src/FFlLib/FFlElementBase.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define FFL_ELEMENT_BASE_H

#include "FFlLib/FFlPartBase.H"
#include "FFlLib/FFlAttributeBase.H"
#include "FFlLib/FFlFEAttributeRefs.H"
#include "FFlLib/FFlFENodeRefs.H"
#ifdef FT_USE_VISUALS
Expand All @@ -17,14 +18,19 @@
#include "FFlLib/FFlTypeInfoSpec.H"
#include "FFaLib/FFaPatterns/FFaGenericFactory.H"

class FFlLinkHandler;
class FFlFEResultBase;
class FFlFEElmResult;
class FFaCheckSum;
class FFaTensor3;
class FaMat33;
class FaVec3;

#ifdef FF_NAMESPACE
namespace FF_NAMESPACE {
#endif

class FFlLinkHandler;


class FFlElementBase : public FFlPartBase,
public FFlFEAttributeRefs,
Expand All @@ -36,7 +42,7 @@ class FFlElementBase : public FFlPartBase,
#endif
{
protected:
typedef std::vector<FFlElementBase*> Elements;
using Elements = std::vector<FFlElementBase*>;

FFlElementBase(int ID = -1);
FFlElementBase(const FFlElementBase& obj);
Expand Down Expand Up @@ -96,11 +102,14 @@ private:
};


typedef FFaGenericFactory<FFlElementBase> ElementFactory;
using ElementFactory = FFaGenericFactory<FFlElementBase>;

#define FFL_FE_ELEMENT_FACTORY_INIT(clName) public: \
static void create(int ID, FFlElementBase*& elm) { elm = new clName(ID); } \
clName& operator=(const clName&) = delete; \
virtual FFlElementBase* clone() const { return new clName(*this); }

#ifdef FF_NAMESPACE
} // namespace
#endif
#endif
59 changes: 40 additions & 19 deletions src/FFlLib/FFlFEAttributeRefs.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "FFaLib/FFaAlgebra/FFaCheckSum.H"
#include "FFaLib/FFaDefinitions/FFaMsg.H"

#ifdef FF_NAMESPACE
namespace FF_NAMESPACE {
#endif


FFlFEAttributeRefs::FFlFEAttributeRefs(const FFlFEAttributeRefs& obj)
{
Expand All @@ -30,8 +34,8 @@ bool FFlFEAttributeRefs::useAttributesFrom(const FFlFEAttributeRefs* obj)
myAttributes.reserve(obj->myAttributes.size());
for (const AttribData& aref : obj->myAttributes)
{
const std::string& typeName = obj->getFEAttributeSpec()->getAttributeName(aref.first);
if (this->getFEAttributeSpec()->getAttributeTypeID(typeName))
const std::string& typeName = obj->getAttributeName(aref.first);
if (this->getAttributeTypeID(typeName))
ok &= this->setAttribute(typeName,aref.second.getID());
}

Expand All @@ -42,7 +46,7 @@ bool FFlFEAttributeRefs::useAttributesFrom(const FFlFEAttributeRefs* obj)
bool FFlFEAttributeRefs::setAttribute(FFlAttributeBase* attrObject)
{
const std::string& type = attrObject->getTypeInfoSpec()->getTypeName();
unsigned char typeID = this->getFEAttributeSpec()->getAttributeTypeID(type);
unsigned char typeID = this->getAttributeTypeID(type);
if (!typeID)
{
std::cerr <<" *** Internal error: \""<< type
Expand Down Expand Up @@ -72,7 +76,7 @@ bool FFlFEAttributeRefs::setAttribute(FFlAttributeBase* attrObject)

bool FFlFEAttributeRefs::setAttribute(const std::string& type, int ID)
{
unsigned char typeID = this->getFEAttributeSpec()->getAttributeTypeID(type);
unsigned char typeID = this->getAttributeTypeID(type);
if (!typeID)
{
if (FFlFEAttributeSpec::isObsolete(type))
Expand Down Expand Up @@ -105,7 +109,7 @@ bool FFlFEAttributeRefs::setAttribute(const std::string& type, int ID)

bool FFlFEAttributeRefs::clearAttribute(const std::string& type)
{
unsigned char typeID = this->getFEAttributeSpec()->getAttributeTypeID(type);
unsigned char typeID = this->getAttributeTypeID(type);
if (typeID)
{
std::pair<AttribsVec::iterator,AttribsVec::iterator> p;
Expand Down Expand Up @@ -156,14 +160,10 @@ bool FFlFEAttributeRefs::hasAttribute(const std::vector<FFlAttributeBase*>& av)
}


// typedefs used in the attribute resolving
typedef std::map<std::string,AttributeMap> AttributeTypeMap;
typedef AttributeTypeMap::const_iterator AttributeTypeMapCIter;

bool FFlFEAttributeRefs::resolve(const AttributeTypeMap& possibleReferences,
bool FFlFEAttributeRefs::resolve(const AttribTypMap& possibleRefs,
bool suppressErrmsg)
{
if (possibleReferences.empty() && !myAttributes.empty())
if (possibleRefs.empty() && !myAttributes.empty())
{
ListUI <<"\n *** Error: No attributes!\n";
return false;
Expand All @@ -174,15 +174,15 @@ bool FFlFEAttributeRefs::resolve(const AttributeTypeMap& possibleReferences,
for (AttribData& attr : myAttributes)
{
// find correct sub-map in the input argument
const std::string& attrName = this->getFEAttributeSpec()->getAttributeName(attr.first);
AttributeTypeMapCIter refIt = possibleReferences.find(attrName);
const std::string& attrName = this->getAttributeName(attr.first);
AttribTypMap::const_iterator refIt = possibleRefs.find(attrName);

// Workaround for conversion of obsolete field names into new name
if (refIt == possibleReferences.end())
if (refIt == possibleRefs.end())
if (attrName == "PBEAMORIENT" || attrName == "PBUSHORIENT")
refIt = possibleReferences.find("PORIENT");
refIt = possibleRefs.find("PORIENT");

if (refIt != possibleReferences.end())
if (refIt != possibleRefs.end())
if (attr.second.resolve(refIt->second))
continue;

Expand All @@ -205,7 +205,7 @@ void FFlFEAttributeRefs::checksum(FFaCheckSum* cs) const

FFlAttributeBase* FFlFEAttributeRefs::getAttribute(const std::string& atType) const
{
unsigned char typeID = this->getFEAttributeSpec()->getAttributeTypeID(atType);
unsigned char typeID = this->getAttributeTypeID(atType);
if (typeID)
{
std::pair<AttribsCIter,AttribsCIter> p;
Expand All @@ -227,7 +227,7 @@ FFlFEAttributeRefs::getAttributes(const std::string& atType) const
{
std::vector<FFlAttributeBase*> retVar;

unsigned char typeID = this->getFEAttributeSpec()->getAttributeTypeID(atType);
unsigned char typeID = this->getAttributeTypeID(atType);
if (typeID)
{
std::pair<AttribsCIter,AttribsCIter> p;
Expand All @@ -247,7 +247,7 @@ FFlFEAttributeRefs::getAttributes(const std::string& atType) const

int FFlFEAttributeRefs::getAttributeID(const std::string& atType) const
{
unsigned char typeID = this->getFEAttributeSpec()->getAttributeTypeID(atType);
unsigned char typeID = this->getAttributeTypeID(atType);
if (typeID)
{
std::pair<AttribsCIter,AttribsCIter> p;
Expand All @@ -260,3 +260,24 @@ int FFlFEAttributeRefs::getAttributeID(const std::string& atType) const
// No message if no attribute of given type or illegal attribute type
return 0;
}


const std::string& FFlFEAttributeRefs::getAttributeName(unsigned char typeID) const
{
FFlFEAttributeSpec* spec = this->getFEAttributeSpec();
if (spec) return spec->getAttributeName(typeID);

static std::string empty;
return empty;
}


unsigned char FFlFEAttributeRefs::getAttributeTypeID(const std::string& name) const
{
FFlFEAttributeSpec* spec = this->getFEAttributeSpec();
return spec ? spec->getAttributeTypeID(name) : 0;
}

#ifdef FF_NAMESPACE
} // namespace
#endif
Loading

0 comments on commit 271b9ff

Please sign in to comment.