Skip to content

Commit

Permalink
Merge pull request #17 from openfedem/exclude-ffacmdlinearg
Browse files Browse the repository at this point in the history
Remove dependencies to FFaCmdLineArg library
  • Loading branch information
kmokstad authored Nov 24, 2024
2 parents 74d9c12 + bf9e678 commit 932d487
Show file tree
Hide file tree
Showing 21 changed files with 241 additions and 204 deletions.
1 change: 0 additions & 1 deletion src/FFaFunctionLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ if ( USE_FORTRAN )
list ( INSERT DEPENDENCY_LIST 1 ${CWave_LIBRARY} )
endif ( CWave_LIBRARY )
endif ( USE_CWAVE )
list ( APPEND DEPENDENCY_LIST FFaCmdLineArg )
else ( USE_FORTRAN )
string ( APPEND CMAKE_CXX_FLAGS " -D_NO_FORTRAN" )
endif ( USE_FORTRAN )
Expand Down
4 changes: 3 additions & 1 deletion src/FFaFunctionLib/FFaUserFuncInterface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ module FFaUserFuncInterface
interface

!> @brief Loads the user-defined plugin(s) into core memory.
!> @param[in] plugin List of user-defined plugin libraries
!> @param[in] funcId Index of function to return number of arguments for
!> @param[out] sign Signature string of the user-defined function plugin
!> @return Number of arguments for specified user-defined function
function ffauf_init (funcId,sign)
function ffauf_init (plugin,funcId,sign)
integer :: ffauf_init
character(len=*), intent(in) :: plugin
integer , intent(in) :: funcId
character(len=*), intent(out) :: sign
end function ffauf_init
Expand Down
56 changes: 29 additions & 27 deletions src/FFaFunctionLib/FFaUserFuncPlugin_F.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,48 @@

#include <cstring>

#include "FFaUserFuncPlugin.H"
#include "FFaLib/FFaCmdLineArg/FFaCmdLineArg.H"
#include "FFaFunctionLib/FFaUserFuncPlugin.H"
#include "FFaLib/FFaString/FFaTokenizer.H"
#include "FFaLib/FFaOS/FFaFortran.H"


INTEGER_FUNCTION(ffauf_init,FFAUF_INIT) (const int& funcId, char* sign, int nc)
{
INTEGER_FUNCTION(ffauf_init,FFAUF_INIT) (const char* plugin,
#ifdef _NCHAR_AFTER_CHARARG
const int ncp, const int& funcId,
char* sign, int nc
#else
const int& funcId, char* sign,
const int ncp, int nc
#endif
){
if (!FFaUserFuncPlugin::instance()->areLibsLoaded())
{
// Get plugin file name from command-line
std::string plugin;
FFaCmdLineArg::instance()->getValue("plugin",plugin);
if (plugin.empty())
{
std::cerr <<"FFaUserFuncPlugin: No plugins specified."<< std::endl;
return -1;
}
else if (plugin[0] == '<')
std::string pluginLib;
if (ncp > 0 && plugin[0] == '<')
{
// We have a multi-file list, find the correct one containing
// user-defined functions (there should only be one)
size_t i;
FFaTokenizer files(plugin,'<','>',',');
for (i = 0; i < files.size(); i++)
if (FFaUserFuncPlugin::instance()->validate(files[i]))
break;

if (i < files.size())
plugin = files[i];
else
{
std::cerr <<"FFaUserFuncPlugin: No valid plugin specified."<< std::endl;
return -2;
}
FFaTokenizer files(std::string(plugin,ncp),'<','>',',');
for (const std::string& file : files)
if (FFaUserFuncPlugin::instance()->validate(file))
{
pluginLib = file;
break;
}
}
else
pluginLib = std::string(plugin,ncp);

if (pluginLib.empty())
{
std::cerr <<"FFaUserFuncPlugin: No valid plugin in \""
<< std::string(plugin,ncp) <<"\"."<< std::endl;
return -2;
}

// Load the user-defined functions plugin and get its signature.
// Pad the string with trailing spaces when returning to Fortran.
if (!FFaUserFuncPlugin::instance()->load(plugin))
if (!FFaUserFuncPlugin::instance()->load(pluginLib))
return -3;
else if (!FFaUserFuncPlugin::instance()->getSign(nc,sign))
memset(sign,' ',nc);
Expand Down
6 changes: 5 additions & 1 deletion src/FFaLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Library setup

set ( LIB_ID FFaLib )
set ( LIB_ID_LIST FFaAlgebra FFaCmdLineArg FFaDefinitions
set ( LIB_ID_LIST FFaAlgebra FFaDefinitions
FFaOperation FFaOS FFaString
)
if ( USE_MEMPOOL )
Expand All @@ -17,11 +17,15 @@ if ( USE_PROFILER )
list ( APPEND LIB_ID_LIST FFaProfiler )
endif ( USE_PROFILER )
if ( "${APPLICATION_ID}" STREQUAL "fedemKernel" )
list ( APPEND LIB_ID_LIST FFaCmdLineArg )
if ( BUILD_TESTS )
list ( APPEND LIB_ID_LIST FFaTests )
endif ( BUILD_TESTS )
else ( "${APPLICATION_ID}" STREQUAL "fedemKernel" )
# These libraries are used by the GUI only
if ( "${APPLICATION_ID}" STREQUAL "fedemGui" )
list ( APPEND LIB_ID_LIST FFaCmdLineArg )
endif ( "${APPLICATION_ID}" STREQUAL "fedemGui" )
if ( USE_CONNECTORS )
list ( APPEND LIB_ID_LIST FFaGeometry )
endif ( USE_CONNECTORS )
Expand Down
10 changes: 3 additions & 7 deletions src/FFlLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ set ( HEADER_FILE_LIST FFlFEResultBase FFlField FFlInit

## Pure implementation files, i.e., source files without corresponding header
set ( SOURCE_FILE_LIST )
if ( "${APPLICATION_ID}" STREQUAL "fedemKernel" )
if ( "${APPLICATION_ID}" STREQUAL "fedemKernel" AND USE_FORTRAN )
set ( SOURCE_FILE_LIST FFlLinkHandler_F )
endif ( "${APPLICATION_ID}" STREQUAL "fedemKernel" )
endif ( "${APPLICATION_ID}" STREQUAL "fedemKernel" AND USE_FORTRAN )

## Fortran 90 source files
set ( F90_FILE_LIST FFlLinkHandlerInterface )
Expand All @@ -105,10 +105,6 @@ endforeach ( FILE ${F90_FILE_LIST} )

set ( DEPENDENCY_LIST FFlFEParts FFaAlgebra FFaDefinitions )

if ( "${APPLICATION_ID}" STREQUAL "fedemKernel" )
list ( INSERT DEPENDENCY_LIST 0 FFlIOAdaptors )
endif ( "${APPLICATION_ID}" STREQUAL "fedemKernel" )

if ( USE_MEMPOOL )
list ( APPEND DEPENDENCY_LIST FFaPatterns )
endif ( USE_MEMPOOL )
Expand All @@ -126,5 +122,5 @@ target_link_libraries ( ${LIB_ID} ${DEPENDENCY_LIST} )

if ( "${APPLICATION_ID}" STREQUAL "fedemKernel" AND USE_FORTRAN )
add_library ( ${LIB_ID}_F ${F90_SOURCE_FILES} )
target_link_libraries ( ${LIB_ID}_F ${LIB_ID} FFaCmdLineArg )
target_link_libraries ( ${LIB_ID}_F ${LIB_ID} FFlIOAdaptors FFaCmdLineArg )
endif ( "${APPLICATION_ID}" STREQUAL "fedemKernel" AND USE_FORTRAN )
19 changes: 19 additions & 0 deletions src/FFlLib/FFlFENodeRefs.C
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,22 @@ bool FFlFENodeRefs::getFaceNodes(std::vector<FFlNode*>& nodes, short int face,

return std::find(nodes.begin(),nodes.end(),(FFlNode*)0) == nodes.end();
}


int FFlFENodeRefs::getNodalCoor(double* X, double* Y, double* Z) const
{
size_t inod = 0;
for (const NodeRef& node : myNodes)
if (node.isResolved())
{
const FaVec3& pos = node->getPos();
X[inod] = pos.x();
Y[inod] = pos.y();
Z[inod] = pos.z();
inod++;
}
else
ListUI <<" *** Error: Element node "<< node.getID() <<" not resolved\n";

return inod == myNodes.size() ? 0 : -3;
}
3 changes: 3 additions & 0 deletions src/FFlLib/FFlFENodeRefs.H
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public:
//! \brief Returns the topological specification of the element.
virtual FFlFEElementTopSpec* getFEElementTopSpec() const = 0;

//! \brief Returns the nodal coordinates for this element.
virtual int getNodalCoor(double* X, double* Y, double* Z) const;

private:
void initNodeVector() const;

Expand Down
72 changes: 63 additions & 9 deletions src/FFlLib/FFlFEParts/FFlBEAM2.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include "FFlLib/FFlFEParts/FFlPORIENT.H"
#include "FFlLib/FFlFEParts/FFlNode.H"
#include "FFaLib/FFaAlgebra/FFaTensor3.H"
#include "FFaLib/FFaAlgebra/FFaMat33.H"
#include "FFaLib/FFaAlgebra/FFaMat34.H"
#include "FFaLib/FFaDefinitions/FFaMsg.H"


void FFlBEAM2::init()
Expand Down Expand Up @@ -87,21 +88,18 @@ bool FFlBEAM2::getVolumeAndInertia(double& volume, FaVec3& cog,
volume = A*L;

// Compute local coordinate system
FFlPORIENT* pori = dynamic_cast<FFlPORIENT*>(this->getAttribute("PORIENT"));
if (!pori) // If no PORIENT, try the equivalent old name also
pori = dynamic_cast<FFlPORIENT*>(this->getAttribute("PBEAMORIENT"));

FaMat33 Telm;
if (pori)
FaVec3 Zaxis = this->getLocalZdirection();
if (Zaxis.isZero())
Telm.makeGlobalizedCS(v2-v1);
else
{
Telm[0] = v2-v1;
Telm[1] = Telm[0] ^ pori->directionVector.getValue();
Telm[1] = Telm[0] ^ Zaxis;
Telm[0].normalize();
Telm[1].normalize();
Telm[2] = Telm[0] ^ Telm[1];
}
else
Telm.makeGlobalizedCS(v2-v1);

// Set up the inertia tensor in local axes
double Ixx = psec->Iy.getValue() + psec->Iz.getValue();
Expand All @@ -114,3 +112,59 @@ bool FFlBEAM2::getVolumeAndInertia(double& volume, FaVec3& cog,
inertia.rotate(Telm.transpose());
return true;
}


int FFlBEAM2::getNodalCoor(double* X, double* Y, double* Z) const
{
int ierr = this->FFlElementBase::getNodalCoor(X,Y,Z);
if (ierr < 0) return ierr;

// Get beam orientation
FaVec3 Zaxis = this->getLocalZdirection();
if (Zaxis.isZero())
{
// No beam orientation given, compute a "globalized" Z-axis
FaMat34 Telm;
Telm.makeGlobalizedCS(FaVec3(X[0],Y[0],Z[0]),FaVec3(X[1],Y[1],Z[1]));
Zaxis = Telm[VZ];
ierr = 1;
ListUI <<" * Note: Computing globalized Z-axis for beam element "
<< this->getID() <<" : "<< Zaxis <<"\n";
}
X[2] = X[0] + Zaxis[0];
Y[2] = Y[0] + Zaxis[1];
Z[2] = Z[0] + Zaxis[2];
X[3] = X[0];
Y[3] = Y[0];
Z[3] = Z[0];
X[4] = X[1];
Y[4] = Y[1];
Z[4] = Z[1];

// Get beam eccentricities, if any
FFlPBEAMECCENT* curEcc = dynamic_cast<FFlPBEAMECCENT*>(this->getAttribute("PBEAMECCENT"));
if (!curEcc) return ierr;

FaVec3 e1 = curEcc->node1Offset.getValue();
FaVec3 e2 = curEcc->node2Offset.getValue();
X[0] += e1[0];
Y[0] += e1[1];
Z[0] += e1[2];
X[1] += e2[0];
Y[1] += e2[1];
Z[1] += e2[2];
X[2] += e1[0];
Y[2] += e1[1];
Z[2] += e1[2];

return ierr;
}


FaVec3 FFlBEAM2::getLocalZdirection() const
{
FFlPORIENT* pori = dynamic_cast<FFlPORIENT*>(this->getAttribute("PORIENT"));
if (!pori) // If no PORIENT, try the equivalent old name also
pori = dynamic_cast<FFlPORIENT*>(this->getAttribute("PBEAMORIENT"));
return pori ? pori->directionVector.getValue() : FaVec3();
}
2 changes: 2 additions & 0 deletions src/FFlLib/FFlFEParts/FFlBEAM2.H
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public:
virtual double getMassDensity() const;
virtual bool getVolumeAndInertia(double& volume, FaVec3& cog,
FFaTensor3& inertia) const;
virtual int getNodalCoor(double* X, double* Y, double* Z) const;
FaVec3 getLocalZdirection() const;

#ifdef FT_USE_MEMPOOL
FFA_MAKE_MEMPOOL;
Expand Down
26 changes: 26 additions & 0 deletions src/FFlLib/FFlFEParts/FFlBUSH.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "FFlLib/FFlFEParts/FFlBUSH.H"
#include "FFlLib/FFlFEParts/FFlPBUSHECCENT.H"


void FFlBUSH::init()
Expand All @@ -25,3 +26,28 @@ void FFlBUSH::init()
FFlBUSHElementTopSpec::instance()->setNodeCount(2);
FFlBUSHElementTopSpec::instance()->setNodeDOFs(6);
}


int FFlBUSH::getNodalCoor(double* X, double* Y, double* Z) const
{
int ierr = this->FFlElementBase::getNodalCoor(X,Y,Z);
if (ierr < 0) return ierr;

X[2] = X[1];
Y[2] = Y[1];
Z[2] = Z[1];
X[1] = X[0];
Y[1] = Y[0];
Z[1] = Z[0];

// Get bushing eccentricity, if any
FFlPBUSHECCENT* curEcc = dynamic_cast<FFlPBUSHECCENT*>(this->getAttribute("PBUSHECCENT"));
if (!curEcc) return ierr;

FaVec3 e1 = curEcc->offset.getValue();
X[0] += e1[0];
Y[0] += e1[1];
Z[0] += e1[2];

return ierr;
}
2 changes: 2 additions & 0 deletions src/FFlLib/FFlFEParts/FFlBUSH.H
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public:
FFL_FE_ATTRIBUTE_SPEC(FFlBUSH);
FFL_TYPE_INFO(FFlBUSH);

virtual int getNodalCoor(double* X, double* Y, double* Z) const;

#ifdef FT_USE_MEMPOOL
FFA_MAKE_MEMPOOL;
#endif
Expand Down
15 changes: 15 additions & 0 deletions src/FFlLib/FFlFEParts/FFlTRI6.C
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,18 @@ bool FFlTRI6::getVolumeAndInertia(double& volume, FaVec3& cog,
FFaVolume::wedMoment(v1,v2,v3,v4,v5,v6,inertia);
return true;
}


int FFlTRI6::getNodalCoor(double* X, double* Y, double* Z) const
{
int ierr = this->FFlElementBase::getNodalCoor(X,Y,Z);
if (ierr < 0) return ierr;

// Reorder the nodes such that the 3 mid-side nodes are ordered last
// 1-2-3-4-5-6 --> 1-3-5-2-4-6
std::swap(X[1],X[2]); std::swap(X[2],X[4]); std::swap(X[3],X[4]);
std::swap(Y[1],Y[2]); std::swap(Y[2],Y[4]); std::swap(Y[3],Y[4]);
std::swap(Z[1],Z[2]); std::swap(Z[2],Z[4]); std::swap(Z[3],Z[4]);

return ierr;
}
1 change: 1 addition & 0 deletions src/FFlLib/FFlFEParts/FFlTRI6.H
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public:

virtual bool getVolumeAndInertia(double& volume, FaVec3& cog,
FFaTensor3& inertia) const;
virtual int getNodalCoor(double* X, double* Y, double* Z) const;

#ifdef FT_USE_MEMPOOL
FFA_MAKE_MEMPOOL;
Expand Down
Loading

0 comments on commit 932d487

Please sign in to comment.