Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required (VERSION 2.6)
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
CMAKE_POLICY (SET CMP0011 NEW)

project (NLA3D)

Expand All @@ -25,10 +26,14 @@ set (NLA3D_BLAS OFF
# CMAKE_BUILD_TYPE empty or Release means the same for us
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -msse2")

# TODO: this should depend on compiler
if(UNIX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -fPIC")
endif()
IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wno-switch")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
ENDIF()

SET (CMAKE_CXX_STANDARD 11)
SET (CMAKE_CXX_STANDARD_REQUIRED TRUE)
SET (CMAKE_CXX_EXTENSION FALSE)

# Linking on Mac Os was not working without this, see `cmake --help-policy CMP0042`
if (APPLE)
Expand Down Expand Up @@ -58,7 +63,7 @@ if (NLA3D_USE_MKL)

find_package(MKL)
if (MKL_FOUND)
include_directories(${MKL_INCLUDE_DIR})
include_directories(SYSTEM ${MKL_INCLUDE_DIR})

# below code works fine only on UNIX systems..
if (MKL_MULTI_THREADED)
Expand All @@ -77,14 +82,15 @@ endif() # NLA3D_USE_MKL

find_package(EASYLOGGINGPP)
if (EASYLOGGINGPP_FOUND)
include_directories(${EASYLOGGINGPP_INCLUDE_DIR})
include_directories(SYSTEM ${EASYLOGGINGPP_INCLUDE_DIR})
else()
message(WARNING "Can't find Easylogging++")
endif()

find_package(EIGEN)
if (EIGEN_FOUND)
include_directories(${EIGEN_INCLUDE_DIR})
# SYSTEM for avoid warnings from the external library
include_directories(SYSTEM ${EIGEN_INCLUDE_DIR})
else()
message(WARNING "Can't find Eigen")
endif()
Expand Down
111 changes: 18 additions & 93 deletions src/FEReaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,6 @@ char sfirstNotBlank(const string& str) {
return str[st];
}


std::vector<std::string> ssplit(const std::string& line, const std::vector<int>& widths, bool strict) {
int ind = 0;
vector<string> vv;
for (int w : widths) {
if (line.length() - ind < w) {
// no room for another field
if (strict) {
LOG(FATAL) << "ssplit: incomplete line: \"" << line << "\"";
} else {
if (line.length() - ind != 0) {
LOG(FATAL) << "ssplit: incomplete field: \"" << line << "\"";
}
return std::move(vv);
}
}
vv.push_back(line.substr(ind, w));
ind += w;
}
return vv;
}


bool iequals(const string& a, const string& b) {
unsigned int sz = a.size();
Expand Down Expand Up @@ -235,9 +213,8 @@ int Tokenizer::tokenize(const string& line) {
}

if (tolower) {
for (int i = 0; i < tokens.size(); i++) {
stolower(tokens[i]);
}
for (auto& token : tokens)
stolower(token);
}
return found;
}
Expand All @@ -254,7 +231,6 @@ double Tokenizer::tokenDouble(size_t ind) {


bool readCdbFile(std::string filename, MeshData& md) {
uint32 n_number, en;
ifstream file(filename);
if (!file) {
LOG(WARNING) << "Can't open cdb file " << filename;
Expand All @@ -271,11 +247,6 @@ bool readCdbFile(std::string filename, MeshData& md) {

std::unordered_map<std::string, double> apdlParameters;

// current element type number. We keep the current element type number while proceed the apld
// file. Currently, this info is not used, but in the past it was used to determine element type
// while parsing EBLOCK blocks.
uint32 type = 0;

Tokenizer t;
// do not convert tokens to lower symbols
t.tolower = false;
Expand Down Expand Up @@ -311,27 +282,17 @@ bool readCdbFile(std::string filename, MeshData& md) {
stolower(strim(line));
std::regex re(R"(\((\d+)i(\d+),(\d+)e(\d+)\.[0-9e]+\))");
std::smatch match;
int int_num;
int int_field;
int float_num;
int float_field;
if (std::regex_match(line, match, re)) {
int_num = std::stoi(match[1]);
int_field = std::stoi(match[2]);
float_num = std::stoi(match[3]);
float_field = std::stoi(match[4]);
} else {
if (!std::regex_match(line, match, re)) {
LOG(FATAL) << "Don't understand nblock format string \"" << line << "\"";
}
size_t const int_num = std::stoi(match[1]);
size_t const int_field = std::stoi(match[2]);
size_t const float_num = std::stoi(match[3]);
size_t const float_field = std::stoi(match[4]);

// prepare array of field widths
std::vector<int> widths;
for (int i = 0; i < int_num; i++) {
widths.push_back(int_field);
}
for (int i = 0; i < float_num; i++) {
widths.push_back(float_field);
}
std::vector<size_t> widths(int_num, int_field);;
widths.insert(widths.end(), float_num, float_field);

// read nodes info line by line
while(!getLine(file, line).eof()) {
Expand Down Expand Up @@ -390,20 +351,14 @@ bool readCdbFile(std::string filename, MeshData& md) {
stolower(strim(line));
std::regex re(R"(\((\d+)i(\d+)\))");
std::smatch match;
int int_num;
int int_field;
if (std::regex_match(line, match, re)) {
int_num = std::stoi(match[1]);
int_field = std::stoi(match[2]);
} else {
if (!std::regex_match(line, match, re)) {
LOG(FATAL) << "Don't understand eblock format string \"" << line << "\"";
}
size_t const int_num = std::stoi(match[1]);
size_t const int_field = std::stoi(match[2]);

// prepare array of field widths
std::vector<int> widths;
for (int i = 0; i < int_num; i++) {
widths.push_back(int_field);
}
std::vector<size_t> widths(int_num, int_field);
// read element data line by line
while(!getLine(file, line).eof()) {
// check for the end of element table
Expand Down Expand Up @@ -450,7 +405,7 @@ bool readCdbFile(std::string filename, MeshData& md) {
LOG(FATAL) << "Not enought fields to read element nodes";
}
// parse element nodes
for (int i = 0; i < nNodes; i++) {
for (uint32 i = 0; i < nNodes; i++) {
enodes.push_back(static_cast<uint32>(std::stoi(v[st + i])));
}

Expand Down Expand Up @@ -495,7 +450,6 @@ bool readCdbFile(std::string filename, MeshData& md) {
while (n_terms > 0) {
getLine(file, line);
t.tokenize(line);
uint16 place = 6;
for (int i = 0; i < std::max(n_terms, 2); i++) {
uint32 node = t.tokenInt(3 + 3 * i + 0);
Dof::dofType dof = Dof::label2dofType(t.tokens[3 + 3 * i + 1]);
Expand Down Expand Up @@ -527,19 +481,13 @@ bool readCdbFile(std::string filename, MeshData& md) {
stolower(strim(line));
std::regex re(R"(\((\d+)i(\d+)\))");
std::smatch match;
int int_num;
int int_field;
if (std::regex_match(line, match, re)) {
int_num = std::stoi(match[1]);
int_field = std::stoi(match[2]);
} else {
if (!std::regex_match(line, match, re)) {
LOG(FATAL) << "Don't understand CMBLOCK format string \"" << line << "\"";
}
size_t const int_num = std::stoi(match[1]);
size_t const int_field = std::stoi(match[2]);
// prepare array of field widths
std::vector<int> widths;
for (int i = 0; i < int_num; i++) {
widths.push_back(int_field);
}
std::vector<size_t> widths(int_num, int_field);;

uint16 in_row = 0;
uint16 all = 0;
Expand Down Expand Up @@ -586,29 +534,6 @@ bool readCdbFile(std::string filename, MeshData& md) {
md.feComps.insert(std::make_pair(comp.name, comp));
}
} //CMBLOCK
else if (iequals(t.tokens[0], "ET") || iequals(t.tokens[0], "ETYPE")) {
// Keep a track on last ET command.. We need this info to know element type.
// If we can convert ET argument into int, then we try to find the APDL parameter in
// apdlParameters dictionary. If it's not there - adpParameters will return new zero value.
// That means, that if parameter is not declared(somehow..) we just put type = 0
// NOTE: in current implementation type value is not used, but it could be used again in the
// future.
try {
type = t.tokenInt(1);
} catch (const std::invalid_argument& ia) {
type = static_cast<uint32>(apdlParameters[t.tokens[1]]);
}
} // ETYPE
else if (iequals(t.tokens[0], "TYPE")) {
// Keep the track on last TYPE command.. We need this info to know element type.
// NOTE: in current implementation type value is not used, but it could be used again in the
// future.
try {
type = t.tokenInt(1);
} catch (const std::invalid_argument& ia) {
type = 0;
}
} // ETYPE
else if (iequals(t.tokens[0], "F")) {
// Dof force record
//f,42,heat,800000.
Expand Down
24 changes: 22 additions & 2 deletions src/FEReaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,28 @@ std::string& stoupper(std::string& str);

// split `line` to substrings with `widths` lengths, if `strict` is false then last substrings could
// be missed
std::vector<std::string> ssplit(const std::string& line, const std::vector<int>& widths,
bool strict = true);
template<typename CONT>
std::vector<std::string> ssplit(std::string const& line, CONT const& widths, bool strict = true) {
size_t ind = 0;
std::vector<std::string> vv;
for (auto const& w : widths) {
if (line.length() < w + ind) {
// no room for another field
if (strict) {
LOG(FATAL) << "ssplit: incomplete line: \"" << line << "\"";
} else {
if (line.length() - ind != 0) {
LOG(FATAL) << "ssplit: incomplete field: \"" << line << "\"";
}
return vv;
}
}
vv.push_back(line.substr(ind, w));
ind += w;
}
return vv;
}


// case insensitive string comparison
bool iequals(const string& a, const string& b);
Expand Down
6 changes: 4 additions & 2 deletions src/lib/FESolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ FESolver::~FESolver() {


void FESolver::attachFEStorage(FEStorage *st) {
CHECK_NOTNULL(st);
if (storage) {
LOG(WARNING) << "FEStorage already is attached. The old one will be dropped.";
}
storage = CHECK_NOTNULL(st);
storage = st;
}


Expand Down Expand Up @@ -166,10 +167,11 @@ void FESolver::deletePostProcessors() {


void FESolver::attachEquationSolver(math::EquationSolver *eq) {
CHECK_NOTNULL(eq);
if (eqSolver) {
LOG(WARNING) << "EquationSolver already is attached. The old one will be dropped.";
}
eqSolver = CHECK_NOTNULL(eq);
eqSolver = eq;
}

void FESolver::initSolutionData() {
Expand Down
5 changes: 0 additions & 5 deletions src/lib/FEStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ namespace nla3d {
using namespace math;


FEStorage::FEStorage() {
};


FEStorage::~FEStorage () {
if (material) {
delete material;
Expand Down Expand Up @@ -533,7 +529,6 @@ void FEStorage::initSolutionData () {
// register MPC coefficients
for (auto mpc : mpcs) {
assert(mpc->eq.size());
uint32 eq_num = mpc->eqNum;
for (auto term : mpc->eq) {
uint32 eq_j = getNodeDofEqNumber(term.node, term.node_dof);
addEntryMPC(mpc->eqNum, eq_j);
Expand Down
1 change: 0 additions & 1 deletion src/lib/FEStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ElementFactory;
// should start from 1 and up to nElements()/nNodes().
class FEStorage {
public:
FEStorage();
~FEStorage();

// A pointer to Material instance. nla3d supports only one material for FE model. External code
Expand Down
6 changes: 1 addition & 5 deletions src/lib/Mpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ void MpcCollection::printEquations (std::ostream& out) {
}
}

RigidBodyMpc::RigidBodyMpc () {

}

RigidBodyMpc::~RigidBodyMpc () {
collection.clear();
}
Expand Down Expand Up @@ -120,7 +116,7 @@ void RigidBodyMpc::update () {
// drivatives for C matrix for i row (with respect to j and l)
Mat<3,3> cDeriv;
for (size_t d = 0; d < dofs.size(); d++) {
uint16 i;
uint16 i = 0;
switch (dofs[d]) {
case Dof::UX:
i = 0;
Expand Down
7 changes: 3 additions & 4 deletions src/lib/Mpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Mpc {

class MpcCollection {
public:
virtual ~MpcCollection() { }
virtual void update() = 0;
virtual void pre() = 0;
void printEquations(std::ostream& out);
Expand All @@ -50,9 +51,8 @@ class MpcCollection {

class RigidBodyMpc : public MpcCollection {
public:
RigidBodyMpc();
~RigidBodyMpc();
uint32 masterNode;
uint32 masterNode = 0;

void pre ();
void update ();
Expand All @@ -74,8 +74,7 @@ class fixBC {

class loadBC {
public:
loadBC () : node(0), node_dof(Dof::UNDEFINED), value(0.0)
{ }
loadBC () { }
loadBC (int32 n, Dof::dofType dof, double val = 0.0) : node(n), node_dof(dof), value(val)
{ }
int32 node = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/PostProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FESolver;
class PostProcessor {
public:
PostProcessor(FEStorage *st);
~PostProcessor() { };
virtual ~PostProcessor() { };
virtual void pre ()=0;
virtual void process (uint16 curLoadstep)=0;
virtual void post (uint16 curLoadstep)=0;
Expand Down
Loading