Commit 6b241b0f by Kirill Terekhov

Updates

Doxygen comments for Automatizator class.

Some additional features for Automatizator class: copy/assignment, list
tags, unregister tag.

Fix compilation issue with Octree example on newer gcc.
parent 199f5aaa
......@@ -134,7 +134,7 @@ void NotMainProcess()
int type = type_C - '0';
//redistribute(&thegrid,type);
pre_redistribute(type);
cout << rank << ": iteration " << iteration++ << " complete. Cells: " << thegrid.mesh->NumberOfCells() << endl;
cout << ::rank << ": iteration " << iteration++ << " complete. Cells: " << thegrid.mesh->NumberOfCells() << endl;
}
if (buff[0] == 'u') // Need remove ghosts
{
......@@ -315,7 +315,7 @@ int main(int argc, char ** argv)
::rank = thegrid.mesh->GetProcessorRank();
//dump_to_vtk();
if (rank == 0) cout << "Test start" << endl;
if (::rank == 0) cout << "Test start" << endl;
{
mx = 0.1;
......@@ -329,24 +329,24 @@ int main(int argc, char ** argv)
{
BARRIER
ct = Timer();
if (rank == 0) LOG(1, "Iteration: " << i)
if (::rank == 0) LOG(1, "Iteration: " << i)
gridAMR(&thegrid,0);
BARRIER
tt = Timer();
if (rank == 0) LOG(1, "AMR time = " << tt-ct);
if (::rank == 0) LOG(1, "AMR time = " << tt-ct);
ct = tt;
redistribute(&thegrid, 0);
BARRIER
tt = Timer();
if (rank == 0) LOG(1, "Red time = " << tt-ct);
if (::rank == 0) LOG(1, "Red time = " << tt-ct);
ct = tt;
LOG(2, rank << ": iteration " << i << " complete. Cells: " << thegrid.mesh->NumberOfCells())
LOG(2, ::rank << ": iteration " << i << " complete. Cells: " << thegrid.mesh->NumberOfCells())
i++;
mx += h;
}
BARRIER
tt = Timer() - tt;
if (rank == 0) cout << "time = " << tt << endl;
if (::rank == 0) cout << "time = " << tt << endl;
dump_to_vtk(&thegrid);
// send_dump_command();
......
......@@ -5,24 +5,10 @@
#include "inmost_mesh.h"
#include "inmost_solver.h"
#include "inmost_variable.h"
#include <sstream> //for debug
//#define NEW_VERSION
//#if defined(USE_AUTODIFF) && (!defined(USE_MESH))
//#warning "USE_AUTODIFF require USE_MESH"
//#undef USE_AUTODIFF
//#endif
//#define DPRNT
#if defined(USE_AUTODIFF)
#include <math.h>
namespace INMOST
{
class Automatizator; //forward declaration
......@@ -128,44 +114,111 @@ namespace INMOST
#endif
#if defined(USE_MESH)
/// The Automatizator class helps in defining primary unknowns of the model and
/// enhances user experience in interaction with automatic differentiation functionality.
/// User may declare real-typed mesh data as primary unknowns on the mesh with the
/// function RegisterTag. The returned integer code can be used with dynamic_variable
/// class, that is part of automatic differentiation framework helping to assemble
/// unknowns or expressions that could be evaluated into variable on the mesh element.
/// In addition this class provides automatic differentiation with acceleration structures
/// that help evaluate expressions faster.
/// \todo
/// 1. UnRegisterTag.
/// 2. (test) Copy constructor.
class Automatizator
{
private:
static Automatizator * CurrentAutomatizator;
static Automatizator * CurrentAutomatizator; //< Currently used automatizator for automatic differentiation acceleration structures.
#if defined(USE_OMP)
std::vector<Sparse::RowMerger> merger;
std::vector<Sparse::RowMerger> merger; //< Automatic differentiation acceleration structures.
#else
Sparse::RowMerger merger;
Sparse::RowMerger merger; //< Automatic differentiation acceleration structures.
#endif
typedef struct{ Tag t; MarkerType domain_mask; } tagdomain;
typedef struct{ tagdomain d; Tag indices; } tagpair;
typedef dynarray<tagpair, 128> tagpairs_type;
typedef std::vector<tagpair> index_enum;
typedef struct{ Tag t, indices; MarkerType domain_mask; bool active;} tagdata; //< Pair of tag and it's mask marker.
typedef std::vector<tagdata> tag_enum; //< A type for an array of registered tags.
typedef std::vector<INMOST_DATA_ENUM_TYPE> del_enum; // A type for an array of deleted positions.
private:
index_enum index_tags;
tagpairs_type reg_tags;
INMOST_DATA_ENUM_TYPE first_num;
INMOST_DATA_ENUM_TYPE last_num;
std::string name; //< Name of the automatizator.
del_enum del_tags; //< Array of deleted positions.
tag_enum reg_tags; //< Array of registered tags.
INMOST_DATA_ENUM_TYPE first_num; //< First index in unknowns of locally owned elements.
INMOST_DATA_ENUM_TYPE last_num; //< Last index in unknowns of locally owned elements.
public:
Automatizator();
/// Make a copy.
/// \warning
/// Calls Automatizator::EnumerateTags after copy for indices
/// to be valid only if original was enumerated.
Automatizator(const Automatizator & b);
/// Performs assignment.
/// \warning
/// Calls Automatizator::EnumerateTags after copy for indices
/// to be valid only if original was enumerated.
Automatizator & operator =(Automatizator const & b);
/// Makes an empty Automatizator.
Automatizator(std::string name = "");
/// Destructor for the automatizator, deletes all the tags corresponding to indices from
/// respective meshes.
~Automatizator();
__INLINE INMOST_DATA_ENUM_TYPE GetFirstIndex() { return first_num; }
__INLINE INMOST_DATA_ENUM_TYPE GetLastIndex() { return last_num; }
/// Retrive first index of unknowns, local to the processor.
__INLINE INMOST_DATA_ENUM_TYPE GetFirstIndex() const { return first_num; }
/// Retrive last index of unknowns, local to the processor.
__INLINE INMOST_DATA_ENUM_TYPE GetLastIndex() const { return last_num; }
/// Set data of tag t defined on domain_mask to be dynamic data.
/// @param t Tag of DATA_REAL that represents independent data of the model.
/// @param typemask Element types on which that data is independent.
/// @param domain_mask Marker that may be used to mask indepndent data on certain elements.
/// \warning
/// Don't register tag twice.
/// 1. Don't register tag twice.
/// 2. Have to call Automatizator::EnumerateTags to compute indices.
/// \todo
/// Read comments inside, change merger.Resize() behavior.
INMOST_DATA_ENUM_TYPE RegisterTag(Tag t, ElementType typemask, MarkerType domain_mask = 0);
INMOST_DATA_ENUM_TYPE RegisterTag(Tag t, ElementType typemask, MarkerType domain_mask = 0);
/// Erase a registered tag.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// \warning
/// 1. Have to call Automatizator::EnumerateTags to recompute indices.
void UnregisterTag(INMOST_DATA_ENUM_TYPE ind);
/// Set index for every data entry of dynamic tag.
void EnumerateTags();
__INLINE Tag GetValueTag(INMOST_DATA_ENUM_TYPE ind) { return reg_tags[ind].d.t; }
__INLINE Tag GetIndexTag(INMOST_DATA_ENUM_TYPE ind) { return reg_tags[ind].indices; }
__INLINE MarkerType GetMask(INMOST_DATA_ENUM_TYPE ind) { return reg_tags[ind].d.domain_mask; }
__INLINE INMOST_DATA_REAL_TYPE GetValue(const Storage & e, INMOST_DATA_ENUM_TYPE ind, INMOST_DATA_ENUM_TYPE comp = 0) { return e->RealArray(GetValueTag(ind))[comp]; }
__INLINE INMOST_DATA_ENUM_TYPE GetIndex(const Storage & e, INMOST_DATA_ENUM_TYPE ind, INMOST_DATA_ENUM_TYPE comp = 0) { return e->IntegerArray(GetIndexTag(ind))[comp]; }
__INLINE bool isValid(const Storage & e, INMOST_DATA_ENUM_TYPE ind) { MarkerType mask = GetMask(ind); return mask == 0 || e->GetMarker(mask); }
Sparse::RowMerger & GetMerger()
void EnumerateTags();
/// Check whether the tag is still registered.
/// @param True if tag is still registered.
__INLINE bool isRegistretedTag(INMOST_DATA_ENUM_TYPE ind) const {return reg_tags[ind].active;}
/// Retrive the tag that is used to store values of the unknown on the mesh.
/// This is the same tag as provided to Automatizator::RegisterTag.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// @return Tag related to values.
__INLINE Tag GetValueTag(INMOST_DATA_ENUM_TYPE ind) const { return reg_tags[ind].t; }
/// Retrive the tag that is used to store indices of the unknown on the mesh.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// @return Tag related to indices.
__INLINE Tag GetIndexTag(INMOST_DATA_ENUM_TYPE ind) const { return reg_tags[ind].indices; }
/// Retrive the mask marker of the registered tag.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// @return Mask marker.
__INLINE MarkerType GetMask(INMOST_DATA_ENUM_TYPE ind) const { return reg_tags[ind].domain_mask; }
/// Retrive the type of elements for the registered tag.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// @return Element types.
ElementType GetElementType(INMOST_DATA_ENUM_TYPE ind) const;
/// Retrive value of the unknown on provided mesh element.
/// @param e Mesh element.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// @return Value of the unknown on element.
__INLINE INMOST_DATA_REAL_TYPE GetValue(const Storage & e, INMOST_DATA_ENUM_TYPE ind, INMOST_DATA_ENUM_TYPE comp = 0) const { return e->RealArray(GetValueTag(ind))[comp]; }
/// Retrive index of the unknown on provided mesh element.
/// @param e Mesh element.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// @return Index of the unknown on element.
__INLINE INMOST_DATA_ENUM_TYPE GetIndex(const Storage & e, INMOST_DATA_ENUM_TYPE ind, INMOST_DATA_ENUM_TYPE comp = 0) const { return e->IntegerArray(GetIndexTag(ind))[comp]; }
/// Check that the data is defined and independent on provided mesh element.
/// @param e Mesh element.
/// @param ind Integer returned from Automatizator::RegisterTag.
/// @return Returns true if the data is defined.
__INLINE bool isValid(const Storage & e, INMOST_DATA_ENUM_TYPE ind) const { MarkerType mask = GetMask(ind); return mask == 0 || e->GetMarker(mask); }
/// Retrive acceleration structure for automatic differentiation.
/// This structure can be used for operations on the matrix.
/// @return Acceleration structure.
Sparse::RowMerger & GetMerger()
{
#if defined(USE_OMP)
return merger[omp_get_thread_num()];
......@@ -173,14 +226,18 @@ namespace INMOST
return merger;
#endif
}
/// Remove global current automatizator.
/// Remove global current automatizator used to set acceleration structures for automatic differentation.
static void RemoveCurrent() {CurrentAutomatizator = NULL;}
/// Set current global automatizator, so that variable will be optimized with row merger.
static void MakeCurrent(Automatizator * aut) {CurrentAutomatizator = aut;}
/// Check that there is an automatizator.
static bool HaveCurrent() {return CurrentAutomatizator != NULL;}
/// Retrive the automatizator.
/// @return Currently set automatizator.
static Automatizator * GetCurrent() {return CurrentAutomatizator;}
/// Lists all the indices of registered tags.
/// @return An array with indices corresponding to all registered tags.
std::vector<INMOST_DATA_ENUM_TYPE> ListRegisteredTags() const;
};
#endif
} //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