Skip to content

Commit

Permalink
import 3rd party script to support for local copies
Browse files Browse the repository at this point in the history
  • Loading branch information
carsten-forty2 committed Aug 22, 2022
2 parents 4cf06f6 + 7c47375 commit 6df915e
Show file tree
Hide file tree
Showing 26 changed files with 503 additions and 176 deletions.
9 changes: 8 additions & 1 deletion core/python/generate_pygimli_code.py
Expand Up @@ -373,7 +373,11 @@ def generate(defined_symbols, extraIncludes):
'getNonEmptyRow',
'getSubstrings',
'abs',
'type']
'type',
'::GIMLI::print',
'print',
'range',
]
)

exclude(main_ns.free_operators,
Expand Down Expand Up @@ -455,6 +459,9 @@ def generate(defined_symbols, extraIncludes):
'IVectorIter',
'RVectorIter',
'FunctionDD',
'::GIMLI::print',
'print',
'range',
]

for c in main_ns.free_functions():
Expand Down
75 changes: 50 additions & 25 deletions core/src/gimli.h
Expand Up @@ -126,12 +126,62 @@ typedef int64_t int64;
#define __FILENAME__ __FILE__
#endif


#ifndef PYGIMLI_CAST // castxml complains on older gcc/clang
inline std::string str(){ return "";}
#endif
//! General template for conversion to string, should supersede all sprintf etc.
template< typename T > inline std::string str(const T & v){
std::ostringstream os;
os << v;
return os.str();
}
enum LogType {Verbose, Info, Warning, Error, Debug, Critical};
DLLEXPORT void log(LogType type, const std::string & msg);


template<typename Value, typename... Values>
std::string str(Value v, Values... vs){
std::ostringstream os;
using expander = int[];
os << v; // first
(void) expander{ 0, (os << " " << vs, void(), 0)... };
return os.str();
}
template<typename... Values>
void log(LogType type, Values... vs){
return log(type, str(vs...));
}

// simple python like std out
inline void print() {
std::cout << std::endl;
}

template<class Head>
void print(std::ostream& s, Head&& head) {
s << std::forward<Head>(head) << std::endl;
}

template<class Head, class... Tail>
void print(std::ostream& s, Head&& head, Tail&&... tail) {
s << std::forward<Head>(head) << " ";
print(s, std::forward<Tail>(tail)...);
}

template<class... Args>
void print(Args&&... args) {
print(std::cout, std::forward<Args>(args)...);
}

#define WHERE GIMLI::str(__FILENAME__) + ":" + GIMLI::str(__LINE__) + "\t"
#define WHERE_AM_I WHERE + "\t" + GIMLI::str(__ASSERT_FUNCTION) + " "
#define TO_IMPL WHERE_AM_I + " not yet implemented\n " + GIMLI::versionStr() + "\nPlease send the messages above, the commandline and all necessary data to the author."

#define __M std::cout << "*** " << WHERE << std::endl;
#define __MS(str) std::cout << "*** " <<str << " " << WHERE << std::endl;
// temporary
#define __MSP(...) GIMLI::print("+++", WHERE, "\n", __VA_ARGS__, "\n---");
#define __D if (debug()) std::cout << "Debug: " << WHERE << std::endl;
#define __DS(str) if (debug()) std::cout << "Debug: " << str << " " << WHERE << std::endl;

Expand Down Expand Up @@ -336,31 +386,6 @@ class DLLEXPORT PythonGILSave {
// #include <Python.h>
#endif

inline std::string str(){ return "";}
//! General template for conversion to string, should supersede all sprintf etc.
template< typename T > inline std::string str(const T & v){
std::ostringstream os;
os << v;
return os.str();
}
enum LogType {Verbose, Info, Warning, Error, Debug, Critical};
DLLEXPORT void log(LogType type, const std::string & msg);

template<typename Value, typename... Values>
std::string str(Value v, Values... vs){
std::ostringstream os;
using expander = int[];
os << v; // first
(void) expander{ 0, (os << " " << vs, void(), 0)... };
return os.str();
}
#ifndef PYGIMLI_CAST // castxml complains on older gcc/clang
#endif
template<typename... Values>
void log(LogType type, Values... vs){
return log(type, str(vs...));
}

DLLEXPORT std::string versionStr();

DLLEXPORT std::string authors();
Expand Down
141 changes: 110 additions & 31 deletions core/src/mesh.cpp
Expand Up @@ -19,12 +19,12 @@
#include "mesh.h"

#include "kdtreeWrapper.h"
#include "line.h"
#include "memwatch.h"
#include "meshentities.h"
#include "node.h"
#include "line.h"
#include "plane.h"
#include "shape.h"

#include "sparsematrix.h"
#include "stopwatch.h"

Expand Down Expand Up @@ -178,6 +178,10 @@ Node * Mesh::createNodeGC_(const RVector3 & pos, int marker){
Index oldCount = this->nodeCount();
Node *n = this->createNodeWithCheck(pos);
n->setMarker(marker);

if ((this->nodeCount() == oldCount)){
if (n->state() == No) n->setState(Original);
}

if ((this->dim() == 3) and (this->nodeCount() > oldCount)){

Expand Down Expand Up @@ -501,15 +505,18 @@ Boundary * findSecParent(const std::vector < Node * > & v){
}
return 0;
}

Boundary * Mesh::copyBoundary(const Boundary & bound, double tol, bool check){
bool debug = false;
#define _D(...) if (debug) __MSP(__VA_ARGS__)
_D("copyBoundary", bound.ids())

std::vector < Node * > nodes(bound.nodeCount());
bool isFreeFace = false;
// bool isSubFace = false;

bool isFreeFace = false; //** the new face is no subface

std::vector < Node * > oldNodes;
std::vector < Node * > conNodes;
std::vector < Node * > secNodes;
std::vector < Node * > subNodes;

// __M
for (Index i = 0; i < nodes.size(); i ++) {
Expand All @@ -519,87 +526,159 @@ Boundary * Mesh::copyBoundary(const Boundary & bound, double tol, bool check){
nodes[i] = createNode(bound.node(i).pos(), tol);
} else {
// 3D poly tests fail!! .. need to be checked and fixed TODO
nodes[i] = createNodeWithCheck(bound.node(i).pos(), tol);
if (check== true){
nodes[i] = createNodeWithCheck(bound.node(i).pos(), tol);
} else {
nodes[i] = createNode(bound.node(i).pos());
}
}
nodes[i]->setMarker(bound.node(i).marker());
// __MS(nodes[i]->state())
switch (nodes[i]->state()){
case NodeState::No:
// at least one node is not in boundary
// at least one node is not inside boundary
isFreeFace = true; break;
case NodeState::Secondary:
secNodes.push_back(nodes[i]); break;
// __MS(*nodes[i])
case NodeState::Connected:
conNodes.push_back(nodes[i]); break;
case NodeState::Original:
oldNodes.push_back(nodes[i]);
break;

}
}
Boundary * b = 0;
Boundary * parent = 0;
Boundary * ret = 0;

if (bound.rtti() == MESH_POLYGON_FACE_RTTI){
std::vector < Node * > subNodes; // nodes for the new subface
if (bound.rtti() == MESH_POLYGON_FACE_RTTI && check == true){

_D("connectedNodes:", conNodes,
"secondaryNodes:", secNodes,
"origNodes:", oldNodes)
_D("new face nodes:", nodes, "is subface", not isFreeFace)

Boundary * conParent = findBoundary(conNodes);
Boundary * secParent = findSecParent(secNodes);

//** identify if face is freeface
if (!isFreeFace){
conParent = findBoundary(conNodes);


std::set < Boundary * > conParentCand = findBoundaries(conNodes);
Boundary * conParent = 0;
if (conParentCand.size() > 0 ){
for (auto *b: conParentCand){
if (b->shape().plane().compare(bound.shape().plane(),
TOLERANCE, true)){
conParent = b;
break;
}
}
}
if (conNodes.size() && secNodes.size()){
if (conParent != secParent){

if (!conParent || conParent != secParent){
isFreeFace = true;
}
subNodes = conNodes;
subNodes.insert(subNodes.end(), secNodes.begin(), secNodes.end());
if (conParent){
_D("conParent", conParent->ids())
} else {
_D("no parent for connected nodes")
}
if (secParent){
_D("secParent", secParent->ids())
} else {
_D("no parent for secondary nodes")
}

// subNodes = conNodes;
// subNodes.insert(subNodes.end(), secNodes.begin(), secNodes.end());
subNodes = nodes;
_D("subNodes", subNodes)
parent = secParent;
}
if (conNodes.size()){
} else if (conNodes.size()){
if (!conParent){
isFreeFace = true;
_D("no conParent")
} else {
_D("conParent", conParent->ids())

if (oldNodes.size()){
//original nodes may not be part of connected Parent
for (auto *n: oldNodes){
if (!conParent->shape().touch(n->pos())) {
_D("node not on connected parent", n->id())
isFreeFace = true;
}
}
}
}
subNodes = conNodes;
subNodes = nodes;
parent = conParent;
}
if (secNodes.size()){
} else if (secNodes.size()){
if(!secParent){
isFreeFace = true;
_D("no secondary parent")
} else if (!secParent->shape().plane().compare(
bound.shape().plane(), TOLERANCE, true)){

_D("secParent", secParent->ids())
_D("secParent.Plane:", secParent->shape().plane());
_D("bound.Plane:", bound.shape().plane());
isFreeFace = true;
}
subNodes = secNodes;
parent = secParent;
} else if (oldNodes.size()){
isFreeFace = true;
}
}


//** create new face
_D("is subface", not isFreeFace, subNodes.size(), nodes.size())

if (isFreeFace){
b = createBoundaryChecked_< PolygonFace >(nodes,
bound.marker(), check);
parent = b;
ret = createBoundaryChecked_< PolygonFace >(nodes,
bound.marker(), check);
_D("added freeFace: ", ret->ids())
parent = ret;
} else {
if (subNodes.size() > 2){
if (parent){
for (auto *n: secNodes){
parent->delSecondaryNode(n);
n->setState(No);
}
auto *p = dynamic_cast< PolygonFace * >(parent);
_D("addSubface: ", p->subfaceCount())
p->addSubface(subNodes);
_D("subfacecount: ", p->subfaceCount())

if (debug) for (auto i: range(p->subfaceCount())){
_D("added subface:", p->subface(i))
}
dynamic_cast< PolygonFace * >(parent)->addSubface(subNodes);
} else {
log(Error, "no parent boundary");
}
b = parent;
ret = parent;
} else {
log(Error, "new subface but only two nodes");
}
}
const PolygonFace & f = dynamic_cast< const PolygonFace & >(bound);
if (f.subfaceCount() > 0){
log(Error, "Can't yet copy a boundary with subfaces");
}

for (Index i = 0; i < f.holeMarkers().size(); i ++ ){
dynamic_cast< PolygonFace* >(parent)->addHoleMarker(
f.holeMarkers()[i]);
}
} else { // if no Polygonface
b = createBoundary(nodes, bound.marker(), check);
ret = createBoundary(nodes, bound.marker(), check);
}

return b;
return ret;
}

Node & Mesh::node(Index i) {
Expand Down Expand Up @@ -1998,7 +2077,6 @@ Mesh Mesh::createSubMesh(const std::vector< Node * > & nodes) const {
return mesh;
}


void Mesh::addData(const std::string & name, const RVector & data) {
// std::cout << "add export Data: " << name << " " << min(data) << " " << max(data) << std::endl;
if (dataMap_.count(name)){
Expand Down Expand Up @@ -2093,6 +2171,7 @@ void Mesh::mapBoundaryMarker(const std::map < int, int > & aMap){
}
}
}

void Mesh::prolongateEmptyCellsValues(RVector & vals, double background) const {
IndexArray emptyList(find(abs(vals) < TOLERANCE));
if (emptyList.size() == 0) return;
Expand Down
11 changes: 7 additions & 4 deletions core/src/meshentities.cpp
Expand Up @@ -18,10 +18,10 @@

#include "meshentities.h"

#include "node.h"
#include "shape.h"
#include "line.h"
#include "mesh.h"
#include "node.h"
#include "shape.h"

#include <map>
#include <algorithm>
Expand Down Expand Up @@ -73,14 +73,17 @@ Boundary * findBoundary(const std::vector < Node * > & n) {
else if (n.size() == 3) return findBoundary(*n[0], *n[1], *n[2]);
else if (n.size() == 4) return findBoundary(*n[0], *n[1], *n[2], *n[3]);

return findBoundary_(findBoundaries(n));
}

std::set < Boundary * > findBoundaries(const std::vector < Node * > & n){
std::vector < std::set< Boundary * > > bs(n.size());

for (uint i = 0; i < n.size(); i ++) bs[i] = n[i]->boundSet();

std::set < Boundary * > common;
intersectionSet(common, bs);

return findBoundary_(common);
return common;
}

Boundary * findCommonBoundary(const Cell & c1, const Cell & c2){
Expand Down

0 comments on commit 6df915e

Please sign in to comment.