Commit 8e6d16ce by Kirill Terekhov

Some updates

thread_private class for static OpenMP objects acts as iterator

EndModification do not unnecessarily delete orphan elements

Fixed Face::getNodes behaviour inside BeginModification and
EndModification region (same fix as in andre_brench)

Added template access functions for AbstractEntry class, allows to get
(matrix of) values, unknown indices or unknowns themselves depending on
template parameter

Examples/OldDrawGrid:
* Adjustments for svg output of color gradient in color bar (previously
was not properly working in Inkscape)
* Preparations for isosurface extraction code
parent 1e58380d
......@@ -262,23 +262,26 @@ namespace INMOST
double px1, py1, z;
double px2, py2;
int height = glutGet(GLUT_WINDOW_HEIGHT);
file << "<g>" << std::endl;
for (int i = 0; i < ticks.size() - 1; ++i)
{
file << "<g>" << std::endl;
colors[i].set_color();
gluProject(left, bottom + ticks[i] * (top - bottom), 0, modelview, projection, viewport, &px1, &py1, &z); py1 = height - py1;
gluProject(right, bottom + ticks[i + 1] * (top - bottom), 0, modelview, projection, viewport, &px2, &py2, &z); py2 = height - py2;
file << "<def>" << std::endl;
file << "<linearGradient id=\"grad" << i << "\" gradientUnits=\"userSpaceOnUse\" x1=\"" << px1 << "\" y1=\"" << py1 << "\" x2=\"" << px1 << "\" y2=\"" << py2 << "\">" << std::endl;
file << "<stop offset=\"0%\" stop-color=\"" << colors[i].svg_rgb() << "\"/>" << std::endl;
file << "<stop offset=\"100%\" stop-color=\"" << colors[i + 1].svg_rgb() << "\"/>" << std::endl;
file << "<defs>" << std::endl;
file << "<linearGradient id=\"grad" << i << "\" x1=\"0%\" y1=\"100%\" x2=\"0%\" y2=\"0%\">" << std::endl;
file << "<stop offset=\"0%\" style=\"stop-color:" << colors[i].svg_rgb() << ";stop-opacity:1\"/>" << std::endl;
file << "<stop offset=\"100%\" style=\"stop-color:" << colors[i + 1].svg_rgb() << ";stop-opacity:1\"/>" << std::endl;
file << "</linearGradient>" << std::endl;
file << "</def>" << std::endl;
file << "<rect stroke=\"none\" x=\"" << px1 << "\" y=\"" << py2 << "\" width=\"" << px2 - px1 << "\" height=\"" << py1 - py2 << "\" fill=\"url(#grad" << i << ")\"/>" << std::endl;
file << "</defs>" << std::endl;
file << "<rect stroke=\"none\" x=\"" << px1 << "\" y=\"" << py2 << "\" width=\"" << fabs(px2 - px1) << "\" height=\"" << fabs(py1 - py2) << "\" fill=\"url(#grad" << i << ")\"/>" << std::endl;
file << "</g>" << std::endl;
}
int tickmarks = 11;
file << "<g>" << std::endl;
for (int i = 0; i < tickmarks; ++i)
{
float t = 1.0f*i / static_cast<float>(tickmarks - 1);
......@@ -294,6 +297,7 @@ namespace INMOST
gluProject(left, bottom, 0, modelview, projection, viewport, &px1, &py1, &z); py1 = height - py1;
gluProject(right, top, 0, modelview, projection, viewport, &px2, &py2, &z); py2 = height - py2;
file << "<rect stroke=\"black\" fill=\"none\" x=\"" << px1 << "\" y=\"" << py2 << "\" width=\"" << px2 - px1 << "\" height=\"" << py1 - py2 << "\"/>" << std::endl;
file << "</g>" << std::endl;
file << "<g stroke=\"black\">" << std::endl;
for (int i = 0; i < tickmarks; ++i)
......@@ -304,11 +308,11 @@ namespace INMOST
svg_line(file, right + (left - right)*0.25, pos, 0, right, pos, 0, modelview, projection, viewport);
}
file << "</g>" << std::endl;
file << "</g>" << std::endl;
//file << "</g>" << std::endl;
}
color_bar * GetColorBar() { return color_bar::GetColorBar(); }
bool isColorBarEnabled() { return color_bar::isColorBarEnabled(); }
Tag GetVisualizationTag() { return color_bar::GetVisualizationTag(); }
}
\ No newline at end of file
}
#ifndef _ISOSURF_H
#define _ISOSURF_H
#include "inmost.h"
#include "coord.h"
#include "octree.h"
namespace INMOST
{
struct triangle
{
int a, b, c;
};
class Isosurface
{
private:
std::vector<coord> points;
std::vector<triangle> tris;
std::vector<double> vals;
public:
Isosurface() {}
Isosurface();
Isosurface(const Isosurface & other) { points = other.points; tris = other.tris; vals = other.vals; }
Isosurface & operator =(Streamline const & other) { points = other.points; tris = other.tris; vals = other.vals; return *this; }
~Isosurface() { points.clear(); tris.clear(); vals.clear() }
void Draw(int reduced);
void SVGDraw(std::ostream & file, double modelview[16], double projection[16], int viewport[4]);
};
void BuildIsosurfaces(Mesh *m, Tag values, double iso, std::vector<Isosurface> & output);
}
#endif
......@@ -1956,7 +1956,11 @@ void svg_draw(std::ostream & file)
{
//file << "<?xml version=\"1.0\" stanfalone=\"no\">" << std::endl;
//file << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" << std::endl;
file << "<svg width=\"" << width << "\" height=\"" << height << "\" version=\"1.1\">" << std::endl;
file << "<svg version=\"1.1\"";
file << " baseProfile=\"full\"";
file << " width=\"" << width << "\"";
file << " height=\"" << height << "\" xmlns=\"http://www.w3.org/2000/svg\">" << std::endl;
//glDepthMask(GL_TRUE);
glLoadIdentity();
......
......@@ -215,7 +215,7 @@ namespace INMOST
Storage::real coef, len, size;
coord next = pos, vel;
Element c;
const int maxsteps = 8000;
const int maxsteps = 250;
points.reserve(maxsteps / 2);
velarr.reserve(maxsteps / 2);
points.push_back(pos);
......
......@@ -11,6 +11,13 @@
namespace INMOST
{
template<> Matrix<INMOST_DATA_REAL_TYPE> AbstractEntry::Access(const Storage& e) const {return Value(e);}
template<> Matrix<INMOST_DATA_INTEGER_TYPE> AbstractEntry::Access(const Storage& e) const {return Index(e);}
template<> Matrix<unknown> AbstractEntry::Access(const Storage& e) const {return Unknown(e);}
template<> INMOST_DATA_REAL_TYPE AbstractEntry::Access(const Storage& e, INMOST_DATA_ENUM_TYPE pos) const {return Value(e,pos);}
template<> INMOST_DATA_INTEGER_TYPE AbstractEntry::Access(const Storage& e, INMOST_DATA_ENUM_TYPE pos) const {return Index(e,pos);}
template<> unknown AbstractEntry::Access(const Storage& e, INMOST_DATA_ENUM_TYPE pos) const {return Unknown(e,pos);}
#if defined(USE_MESH)
Automatizator * Automatizator::CurrentAutomatizator = NULL;
......@@ -127,16 +134,26 @@ namespace INMOST
}
reg_blocks[ret]->reg_index = ret;
//b.reg_index = ret;
{
std::stringstream tag_name;
tag_name << name << "_BLK_" << ret << "_Offset";
reg_blocks[ret]->SetOffsetTag(m->CreateTag(tag_name.str(),DATA_INTEGER,b.GetElementType(),sparse,1));
//b.SetOffsetTag(reg_blocks[ret]->GetOffsetTag());
}
return ret;
}
INMOST_DATA_ENUM_TYPE Automatizator::RegisterEntry(AbstractEntry & b)
{
INMOST_DATA_ENUM_TYPE ret = RegisterEntry(static_cast<const AbstractEntry &>(b));
b.reg_index = reg_blocks[ret]->GetRegistrationIndex();
b.SetOffsetTag(reg_blocks[ret]->GetOffsetTag());
return ret;
}
void Automatizator::UnregisterEntry(INMOST_DATA_ENUM_TYPE ind)
{
assert(reg_blocks[ind]);
......
......@@ -2779,26 +2779,28 @@ namespace INMOST
}
return *this;
}
operator T & () {return items[omp_get_thread_num()].item;}
operator const T & () const {return items[omp_get_thread_num()].item;}
T & operator *() {return items[omp_get_thread_num()].item;}
const T & operator *() const {return items[omp_get_thread_num()].item;}
//operator T & () {return items[omp_get_thread_num()].item;}
//operator const T & () const {return items[omp_get_thread_num()].item;}
//operator T () {return items[omp_get_thread_num()].item;}
//operator T () const {return items[omp_get_thread_num()].item;}
template <typename B>
T & operator = (B const & b) {items[omp_get_thread_num()].item = b; return items[omp_get_thread_num()].item;}
template <typename B>
T & operator += (B const & b) {items[omp_get_thread_num()].item += b; return items[omp_get_thread_num()].item;}
template <typename B>
T & operator -= (B const & b) {items[omp_get_thread_num()].item -= b; return items[omp_get_thread_num()].item;}
template <typename B>
T & operator *= (B const & b) {items[omp_get_thread_num()].item *= b; return items[omp_get_thread_num()].item;}
template <typename B>
T & operator /= (B const & b) {items[omp_get_thread_num()].item /= b; return items[omp_get_thread_num()].item;}
//template <typename B>
//T & operator = (B const & b) {items[omp_get_thread_num()].item = b; return items[omp_get_thread_num()].item;}
//template <typename B>
//T & operator += (B const & b) {items[omp_get_thread_num()].item += b; return items[omp_get_thread_num()].item;}
//template <typename B>
//T & operator -= (B const & b) {items[omp_get_thread_num()].item -= b; return items[omp_get_thread_num()].item;}
//template <typename B>
//T & operator *= (B const & b) {items[omp_get_thread_num()].item *= b; return items[omp_get_thread_num()].item;}
//template <typename B>
//T & operator /= (B const & b) {items[omp_get_thread_num()].item /= b; return items[omp_get_thread_num()].item;}
T & get() {return items[omp_get_thread_num()].item;}
const T & get() const {return items[omp_get_thread_num()].item;}
T & get(int k) {return items[k].item;}
const T & get(int k) const {return items[k].item;}
T & operator ->() {return get();}
const T & operator ->() const {return get();}
T * operator ->() {return get();}
const T * operator ->() const {return get();}
};
#else //_OPENMP
template<typename T>
......@@ -2811,26 +2813,28 @@ namespace INMOST
thread_private(const T & b) {item = b;}
thread_private(const thread_private & b) {item = b();}
thread_private & operator = (thread_private const & b) {item = b(); return *this;}
operator T & () {return item;}
operator const T & () const {return item;}
T & operator *() {return item;}
const T & operator *() const {return item;}
//operator T & () {return item;}
//operator const T & () const {return item;}
//operator T () {return items[omp_get_thread_num()].item;}
//operator T () const {return items[omp_get_thread_num()].item;}
template <typename B>
T & operator = (B const & b) {item = b; return item;}
template <typename B>
T & operator += (B const & b) {item += b; return item;}
template <typename B>
T & operator -= (B const & b) {item -= b; return item;}
template <typename B>
T & operator *= (B const & b) {item *= b; return item;}
template <typename B>
T & operator /= (B const & b) {item /= b; return item;}
//template <typename B>
//T & operator = (B const & b) {item = b; return item;}
//template <typename B>
//T & operator += (B const & b) {item += b; return item;}
//template <typename B>
//T & operator -= (B const & b) {item -= b; return item;}
//template <typename B>
//T & operator *= (B const & b) {item *= b; return item;}
//template <typename B>
//T & operator /= (B const & b) {item /= b; return item;}
T & get() {return item;}
const T & get() const {return item;}
T & get(int k) {return item;}
const T & get(int k) const {return item;}
T & operator ->() {return get();}
const T & operator ->() const {return get();}
T * operator ->() {return &item;}
const T * operator ->() const {return &item;}
};
#endif //_OPENMP
/*
......
......@@ -42,17 +42,17 @@ namespace INMOST
/// Check that the block is valid on given element.
bool isValid(const Storage & e) const {return reg_index != ENUMUNDEF && (e.GetElementType() & etype) && (mask == 0 || e->GetMarker(mask));}
/// Return value in vector of unknowns of the block at certain position.
/// @param pos Position for which to extract the value, should be no larger the MatrixSize.
/// @param pos Position for which to extract the value, should be no larger then MatrixSize.
virtual INMOST_DATA_REAL_TYPE Value(const Storage & e, INMOST_DATA_ENUM_TYPE pos) const = 0;
/// Return value in vector of unknowns of the block at certain position.
/// @param pos Position for which to extract the value, should be no larger the MatrixSize.
/// @param pos Position for which to extract the value, should be no larger then MatrixSize.
virtual INMOST_DATA_REAL_TYPE & Value(const Storage & e, INMOST_DATA_ENUM_TYPE pos) = 0;
/// Return index in vector of indices of the block at certain position.
/// The index may be ENUMUNDEF if the unknown is inactive.
/// @param pos Position for which to extract the index, should be no larger the MatrixSize.
/// @param pos Position for which to extract the index, should be no larger then MatrixSize.
virtual INMOST_DATA_ENUM_TYPE Index(const Storage & e, INMOST_DATA_ENUM_TYPE pos) const = 0;
/// Return unknown in vector of variables of the block at certain position.
/// @param pos Position for which to extract the unknown, should be no larger the MatrixSize.
/// @param pos Position for which to extract the unknown, should be no larger then MatrixSize.
virtual unknown Unknown(const Storage & e, INMOST_DATA_ENUM_TYPE pos) const = 0;
/// Return vector filled with values of unknowns of the block.
virtual rMatrix Value(const Storage & e) const = 0;
......@@ -60,6 +60,13 @@ namespace INMOST
virtual iMatrix Index(const Storage & e) const = 0;
/// Return vector filled with unknowns of the block with their derivatives.
virtual uMatrix Unknown(const Storage & e) const = 0;
/// Return vector filled with either values or indices or unknowns of the block,
/// depending on the template parameter.
template<typename T> Matrix<T> Access(const Storage &e) const;
/// Return either value or index or unknown at specified position of the block,
/// depending on the template parameter.
/// @param pos Position in the block, should be no larger then MatrixSize.
template<typename T> T Access(const Storage &e, INMOST_DATA_ENUM_TYPE pos) const;
/// Return vector filled with unknowns of the block with their derivatives.
virtual uMatrix operator [](const Storage & e) const = 0;
/// The intended size of the matrix for this entry.
......@@ -91,6 +98,9 @@ namespace INMOST
friend class Automatizator; //provide registration index from inside of Automatizator
friend class Model; //provide registration index from inside of Model
};
/// This class is used to organize unknowns into blocks,
/// blocks enumeration are managed by class Automatizator.
class BlockEntry : public AbstractEntry
......@@ -390,6 +400,7 @@ namespace INMOST
/// \warning
/// 1. If you create your entry with intention to use it after registration, then you should use the function as entry = aut.GetEntry(aut.RegisterEntry(entry));
INMOST_DATA_ENUM_TYPE RegisterEntry(const AbstractEntry & e);
INMOST_DATA_ENUM_TYPE RegisterEntry(AbstractEntry & e);
/// Erase a registered tag.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// \warning
......
......@@ -781,23 +781,27 @@ namespace INMOST
}
}
adj_type::size_type it = 1, iend = lc.size()-1;
while(it < iend) if( !m->GetMarker(lc[it],hm) ) //loop over edges
while (m->GetMarker(lc[iend],hm) && iend > 0) iend--;
while(it < iend)
{
adj_type const & ilc = m->LowConn(lc[it]);
k1 = ENUMUNDEF;
k1 = m->getNext(ilc.data(),static_cast<enumerator>(ilc.size()),k1,hm);
k2 = m->getNext(ilc.data(),static_cast<enumerator>(ilc.size()),k1,hm);
if( last == ilc[k1] )
{
if( invert ^ m->GetMarker(ilc[k2],mask) )
aret.push_back(ilc[k2]);
last = ilc[k2];
}
else
if( !m->GetMarker(lc[it],hm) ) //loop over edges
{
if( invert ^ m->GetMarker(ilc[k1],mask) )
aret.push_back(ilc[k1]);
last = ilc[k1];
adj_type const & ilc = m->LowConn(lc[it]);
k1 = ENUMUNDEF;
k1 = m->getNext(ilc.data(),static_cast<enumerator>(ilc.size()),k1,hm);
k2 = m->getNext(ilc.data(),static_cast<enumerator>(ilc.size()),k1,hm);
if( last == ilc[k1] )
{
if( invert ^ m->GetMarker(ilc[k2],mask) )
aret.push_back(ilc[k2]);
last = ilc[k2];
}
else
{
if( invert ^ m->GetMarker(ilc[k1],mask) )
aret.push_back(ilc[k1]);
last = ilc[k1];
}
}
++it;
}
......
......@@ -1674,6 +1674,16 @@ namespace INMOST
//ApplyModification();
//temp_hide_element = hide_element;
//hide_element = 0;
for(ElementType etype = FACE; etype >= NODE; etype = PrevElementType(etype))
{
for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) )
{
//all upper elements are deleted
if( ElementByLocalID(etype,it).nbAdjElements(NextElementType(etype),hide_element) ==
ElementByLocalID(etype,it).nbAdjElements(NextElementType(etype)) )
SetMarker(ComposeHandle(etype,it),hide_element);
}
}
for(ElementType etype = ESET; etype >= NODE; etype = PrevElementType(etype))
{
for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) )
......@@ -1684,6 +1694,7 @@ namespace INMOST
Destroy(h);
}
}
/*
for(ElementType etype = FACE; etype >= NODE; etype = PrevElementType(etype))
{
for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) )
......@@ -1692,6 +1703,7 @@ namespace INMOST
Destroy(ComposeHandle(etype,it));
}
}
*/
RecomputeParallelStorage(ESET|CELL|FACE|EDGE|NODE);
memset(hidden_count,0,sizeof(integer)*6);
memset(hidden_count_zero,0,sizeof(integer)*6);
......
......@@ -5,7 +5,7 @@
#include "../Misc/utils.h"
#include "solver_prototypes.hpp"
#include "solver_bcgsl.hpp"
#define KSOLVER BCGSL_solver
#define KSOLVER BCGS_solver
namespace INMOST {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment