Skip to content

Commit

Permalink
CORE: cut SRC_DIR from debug messages, remove some compiler warnings,…
Browse files Browse the repository at this point in the history
… cherrypick stopwatch from nf branch
  • Loading branch information
carsten-forty2 committed Dec 14, 2022
1 parent 01b7fae commit 7d46410
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 107 deletions.
2 changes: 2 additions & 0 deletions core/config.cmake.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#define PACKAGE_VERSION @PACKAGE_VERSION@

#define SRC_DIR "@CMAKE_SOURCE_DIR@"

#define HAVE_BOOST_INTERPROCESS_MANAGED_SHARED_MEMORY_HPP @HAVE_BOOST_INTERPROCESS_MANAGED_SHARED_MEMORY_HPP@

#define BOOST_THREAD_FOUND @Boost_THREAD_FOUND@
Expand Down
4 changes: 2 additions & 2 deletions core/python/pygimli.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ DEFINE_XVECTOR_STUFF__(RVector) //RVector last since auto rhs conversion will fa
template CSparseMatrix operator * (const CSparseMatrix & A, const GIMLI::Complex & b);

template class ElementMatrix< double >;
template std::ostream & operator << (std::ostream & str,
const ElementMatrix< double > & p);
// template std::ostream & operator << (std::ostream & str,
// const ElementMatrix< double > & p);

template RVector unique(const RVector & a);
// template IndexArray unique(const IndexArray & a);
Expand Down
9 changes: 8 additions & 1 deletion core/src/gimli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,19 @@ std::vector < std::string > split(const std::string & str, char delimiter){
return subStrings;
}

std::string replace(const std::string & str, const std::string & from,
const std::string & to){
std::string ret(str);
if (ret.find(from) != std::string::npos){
ret.replace(ret.find(from), from.length(), to);
}
return ret;
}
std::string replace(const std::string & str, char from, char to){
std::string ret(str);
std::replace(ret.begin(), ret.end(), from, to);
return ret;
}

std::string lower(const std::string & str){
std::string lo(str);
std::transform(lo.begin(), lo.end(), lo.begin(), tolower);
Expand Down
18 changes: 15 additions & 3 deletions core/src/gimli.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,23 @@ typedef int64_t int64;
#endif
#endif


/*!Replace from with to inside str and return the result*/
DLLEXPORT std::string replace(const std::string & str,
const std::string & from,
const std::string & to);

#ifndef SRC_DIR
#define SRC_DIR "./"
#endif

#ifdef _WIN64__
#define __FILENAME__ std::max<const char*>(__FILE__,\
std::max(strrchr(__FILE__, '\\')+1, strrchr(__FILE__, '/')+1))
/// testme and refactor with below # 1.3.1
#define __FILENAME__ GIMLI::replace(__FILE__, SRC_DIR, ".")
// #define __FILENAME__ std::max<const char*>(__FILE__,\
// std::max(strrchr(__FILE__, '\\')+1, strrchr(__FILE__, '/')+1))
#else
#define __FILENAME__ __FILE__
#define __FILENAME__ GIMLI::replace(__FILE__, SRC_DIR, ".")
#endif


Expand Down
27 changes: 17 additions & 10 deletions core/src/kdtreeWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,39 @@

#include "node.h"

double _Node_Bracket_accessor:: operator()(GIMLI::Node * n, size_t i) const {
return n->pos()[i];
}

namespace GIMLI{

inline double tac( Node * n, size_t i ) { return n->pos()[ i ]; }
// inline double tac(Node * n, size_t i) {
// return n->pos()[i];
// }

KDTreeWrapper::KDTreeWrapper(){
tree_ = new NodeKDTree( std::ptr_fun( tac ) );
tree_ = new NodeKDTree();
// tree_ = new NodeKDTree(std::ptr_fun(tac));
}

KDTreeWrapper::~KDTreeWrapper(){
if ( tree_ ) delete tree_;
if (tree_) delete tree_;
}

void KDTreeWrapper::insert( Node * node ){
tree_->insert( node );
void KDTreeWrapper::insert(Node * node){
tree_->insert(node);
}

Node * KDTreeWrapper::nearest( const RVector3 & pos ){
Node testNode( pos );
return *tree_->find_nearest( &testNode ).first;
Node * KDTreeWrapper::nearest(const RVector3 & pos){
Node testNode(pos);
return *tree_->find_nearest(&testNode).first;
}

uint KDTreeWrapper::size( ) const{
uint KDTreeWrapper::size() const{
return tree_->size();
}

NodeKDTree * KDTreeWrapper::tree() {
NodeKDTree * KDTreeWrapper::tree(){
return tree_;
}

Expand Down
7 changes: 6 additions & 1 deletion core/src/kdtreeWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
//#define KDTREE_DEFINE_OSTREAM_OPERATORS
#include <kdtree++/kdtree.hpp>

typedef KDTree::KDTree< 3, GIMLI::Node *, std::pointer_to_binary_function< GIMLI::Node *, size_t, double > > NodeKDTree;
struct _Node_Bracket_accessor {
typedef double result_type;
result_type operator()(GIMLI::Node * n, size_t i) const;
};

typedef KDTree::KDTree< 3, GIMLI::Node *, _Node_Bracket_accessor > NodeKDTree;

namespace GIMLI{

Expand Down
12 changes: 7 additions & 5 deletions core/src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include "sparsematrix.h"
#include "stopwatch.h"

#include <boost/bind.hpp>

#include <map>

namespace GIMLI{
Expand Down Expand Up @@ -1133,7 +1131,7 @@ void Mesh::setCellMarkers(const RVector & attribute){
IVector Mesh::cellMarkers() const{
IVector tmp(cellCount());
std::transform(cellVector_.begin(), cellVector_.end(), tmp.begin(),
std::mem_fn(&Cell::marker));
std::mem_fn(&Cell::marker));
return tmp;
}

Expand Down Expand Up @@ -2517,8 +2515,12 @@ void Mesh::fillKDTree_() const {
if (tree_->size() != nodeCount(true)){

if (tree_->size() == 0){
for_each(nodeVector_.begin(), nodeVector_.end(), boost::bind(&KDTreeWrapper::insert, tree_, _1));
for_each(secNodeVector_.begin(), secNodeVector_.end(), boost::bind(&KDTreeWrapper::insert, tree_, _1));
// for_each(nodeVector_.begin(), nodeVector_.end(), boost::bind(&KDTreeWrapper::insert, tree_, _1));
// for_each(secNodeVector_.begin(), secNodeVector_.end(), boost::bind(&KDTreeWrapper::insert, tree_, _1));
for_each(nodeVector_.begin(), nodeVector_.end(),
[&](Node * n){tree_->insert(n);});
for_each(secNodeVector_.begin(), secNodeVector_.end(),
[&](Node * n){tree_->insert(n);});

tree_->tree()->optimize();
} else {
Expand Down
20 changes: 7 additions & 13 deletions core/src/mesh_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,10 +912,6 @@ void Mesh::exportVTK(const std::string & fbody,
}
file << std::endl;

RVector tmp(boundaryCount());
std::transform(boundaryVector_.begin(), boundaryVector_.end(),
&tmp[0], std::mem_fun(&Boundary::marker));

if (!bData.count("Marker")) bData["Marker"] = this->boundaryMarkers();

if (bData.size() > 0){
Expand Down Expand Up @@ -1312,9 +1308,9 @@ void Mesh::exportVTU(const std::string & fbody, bool binary) const {

std::map< std::string, RVector > data(dataMap_);
if (cellCount() > 0){
RVector tmp(cellCount());
std::transform(cellVector_.begin(), cellVector_.end(), &tmp[0], std::mem_fun(&Cell::marker));
if (!data.count("_Marker")) data.insert(std::make_pair("_Marker", tmp));
if (!data.count("_Marker")) {
data.insert(std::make_pair("_Marker", this->cellMarkers()));
}
if (!data.count("_Attribute")) data.insert(std::make_pair("_Attribute", cellAttributes()));
}
addVTUPiece_(file, *this, data);
Expand Down Expand Up @@ -1350,12 +1346,10 @@ void Mesh::exportBoundaryVTU(const std::string & fbody, bool binary) const {
//for (uint i =0; i < boundMesh.nodeCount(); i ++) std::cout << boundMesh.node(i)<< std::endl;
std::map< std::string, RVector > boundData;

RVector tmp(boundMesh.boundaryCount());
std::transform(boundMesh.boundaries().begin(),
boundMesh.boundaries().end(),
&tmp[0], std::mem_fun(&Boundary::marker));

if (!boundData.count("_BoundaryMarker")) boundData.insert(std::make_pair("_BoundaryMarker", tmp));
if (!boundData.count("_BoundaryMarker")) {
boundData.insert(std::make_pair("_BoundaryMarker",
this->boundaryMarkers()));
}

//boundMesh.exportVTK(fbody, boundData);
addVTUPiece_(file, boundMesh, boundData);
Expand Down
41 changes: 1 addition & 40 deletions core/src/optionmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,47 +148,8 @@ class DLLEXPORT OptionMap{
void printHelp(const std::string & main);

OptionBase * findOption(const char & key) const {
//std::cout << "OptionBase * findOption(const char & key) const {" << std::endl;
log(Warning, "command line parsing from core is obsolete and will be replaced.");
THROW_TO_IMPL
std::list < OptionBase * >::iterator it;

std::cout << std::equal_to< char >()(key, 'h') << std::endl;
std::cout << std::equal_to< char >()(key, 'd') << std::endl;

if (options_.size() > 0){
std::cout << "tn: " << (*options_.begin())->typname() << std::endl;
std::cout << std::mem_fun(&OptionBase::typname)(*options_.begin()) << std::endl;
std::cout << "key: " << (*options_.begin())->key() << std::endl;
std::cout << std::mem_fun(&OptionBase::key)(*options_.begin()) << std::endl;

std::cout << "cmp: " << std::equal_to< char >()(key,
std::mem_fun(&OptionBase::key)(*options_.begin()))
<< std::endl;

std::cout << "cmp: " << std::bind2nd(std::equal_to< char >(), key)('d') << std::endl;
std::cout << "cmp: " << std::bind2nd(std::equal_to< char >(), key)('h') << std::endl;

//** na schon fast, das geht leider noch nicht
// std::cout << "cmp: " << std::bind2nd< std::mem_fun(&OptionBase::key) >(
// std::equal_to< char >(), key)(*options_.begin()) << std::endl;


// std::mem_fun(&OptionBase::key)))(*options_.begin())
// << std::endl;

}
// it = std::find_if(options_.begin(), options_.end(),
// std::equal_to< char >()(key,
// std::mem_fun(&OptionBase::key)(*options_.begin())));
// std::equal_to< char > (std::mem_fun(&Option::key), key));

//std::cout << *it << std::endl;
/*
if (it != options_.end()) {
return *it;
} else {
return NULL;
}*/
return NULL;
}

Expand Down
69 changes: 48 additions & 21 deletions core/src/stopwatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,34 @@
******************************************************************************/

#include "stopwatch.h"
#include "vector.h"

#include <iostream>

namespace GIMLI{

Stopwatch::Stopwatch( bool start ) {
state_ = undefined;
if ( start ) this->start();
Stopwatch::Stopwatch(bool start) : _store(nullptr) {
//newPtr(_store);
_state = undefined;
if (start) this->start();
this->_store = new RVector();
}

Stopwatch::~Stopwatch() {
// deletePtr(this->_store);
delete this->_store;
}

void Stopwatch::start(){
ftime( & starttime );
state_ = running;
cCounter_.tic();
this->_start = std::chrono::high_resolution_clock::now();
_state = running;
_cCounter.tic();
}

void Stopwatch::stop( bool verbose ){
ftime( & stoptime );
state_ = halted;
if ( verbose ) std::cout << "time: " << duration() << "s" << std::endl;
void Stopwatch::stop(bool verbose){
this->_stop = std::chrono::high_resolution_clock::now();
_state = halted;
if (verbose) std::cout << "time: " << duration() << "s" << std::endl;
}

void Stopwatch::restart(){
Expand All @@ -49,22 +54,44 @@ void Stopwatch::restart(){

void Stopwatch::reset(){
restart();
this->_store->clear();
}

double Stopwatch::duration( bool res ){
if ( state_ == undefined ) std::cerr << "Stopwatch not started!" << std::endl;
if ( state_ == running ) ftime( &stoptime );
double t = ( stoptime.time - starttime.time ) + double( stoptime.millitm - starttime.millitm ) / 1000.0;
if ( res ) restart();
return t;
double Stopwatch::duration(bool restart){
std::chrono::time_point<std::chrono::high_resolution_clock> now;

if (_state == undefined) {
log(Error, "Stopwatch not started!");
}

if (_state == running) {
//ftime(&stoptime);
// double t = (stoptime.time - starttime.time) +
// double(stoptime.millitm - starttime.millitm) / 1000.0;

now = std::chrono::high_resolution_clock::now();
} else {
now = this->_stop;
}

std::chrono::duration< double > t = now - this->_start;

if (restart) this->restart();
return t.count();
}

void Stopwatch::store(bool restart){
this->_store->push_back(this->duration(restart));
}

size_t Stopwatch::cycles( bool res ){
if ( state_ == undefined ) std::cerr << "Stopwatch not started!" << std::endl;
size_t Stopwatch::cycles(bool res){
if (_state == undefined) {
log(Error, "Stopwatch not started!");
}
size_t t = 0;
if ( state_ == running ) t = cCounter_.toc();
if ( res ) restart();
if (_state == running) t = _cCounter.toc();
if (res) restart();
return t;
}

} // namespace GIMLI
} // namespace GIMLI
Loading

0 comments on commit 7d46410

Please sign in to comment.