diff --git a/src/io/dumper/dumpable_inline_impl.hh b/src/io/dumper/dumpable_inline_impl.hh index 8d35d35ea..32a5773e0 100644 --- a/src/io/dumper/dumpable_inline_impl.hh +++ b/src/io/dumper/dumpable_inline_impl.hh @@ -1,136 +1,135 @@ /** * @file dumpable_inline_impl.hh * * @author Guillaume Anciaux * @author David Simon Kammer * @author Nicolas Richart * * @date creation: Wed Nov 13 2013 * @date last modification: Mon Sep 15 2014 * * @brief Implementation of the Dumpable class * * @section LICENSE * * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ #ifndef __AKANTU_DUMPABLE_INLINE_IMPL_HH__ #define __AKANTU_DUMPABLE_INLINE_IMPL_HH__ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER #include "dumper_elemental_field.hh" #include "dumper_nodal_field.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ template inline void Dumpable::registerDumper(const std::string & dumper_name, const std::string & file_name, const bool is_default) { AKANTU_DEBUG_ASSERT(this->dumpers.find(dumper_name) == this->dumpers.end(), "Dumper " + dumper_name + "is already registered."); std::string name = file_name; if (name == "") name = dumper_name; this->dumpers[dumper_name] = new T(name); if (is_default) this->default_dumper = dumper_name; } /* -------------------------------------------------------------------------- */ - template inline void Dumpable::addDumpFieldExternal(const std::string & field_id, const Array & field) { this->addDumpFieldExternalToDumper(this->default_dumper, field_id, field); }; /* -------------------------------------------------------------------------- */ template inline void Dumpable::addDumpFieldExternalToDumper(const std::string & dumper_name, const std::string & field_id, const Array & field) { dumper::Field * field_cont = new dumper::NodalField(field); DumperIOHelper & dumper = this->getDumper(dumper_name); dumper.registerField(field_id, field_cont); } /* -------------------------------------------------------------------------- */ template inline void Dumpable::addDumpFieldExternal(const std::string & field_id, const ElementTypeMapArray & field, UInt spatial_dimension, const GhostType & ghost_type, const ElementKind & element_kind) { this->addDumpFieldExternalToDumper(this->default_dumper, field_id, field, spatial_dimension, ghost_type, element_kind); } /* -------------------------------------------------------------------------- */ template inline void Dumpable::addDumpFieldExternalToDumper(const std::string & dumper_name, const std::string & field_id, const ElementTypeMapArray & field, UInt spatial_dimension, const GhostType & ghost_type, const ElementKind & element_kind) { dumper::Field * field_cont = new dumper::ElementalField(field, spatial_dimension, ghost_type, element_kind); DumperIOHelper & dumper = this->getDumper(dumper_name); dumper.registerField(field_id, field_cont); } /* -------------------------------------------------------------------------- */ template inline T & Dumpable::getDumper(const std::string & dumper_name) { DumperIOHelper & dumper = this->getDumper(dumper_name); try { T & templated_dumper = dynamic_cast(dumper); return templated_dumper; } catch (...) { AKANTU_EXCEPTION("Dumper " << dumper_name << " is not of type: " << debug::demangle(typeid(T).name())); } } __END_AKANTU__ #endif #endif /* __AKANTU_DUMPABLE_INLINE_IMPL_HH__ */ diff --git a/src/io/dumper/dumper_compute.hh b/src/io/dumper/dumper_compute.hh index 6cf89b606..8cde05f4b 100644 --- a/src/io/dumper/dumper_compute.hh +++ b/src/io/dumper/dumper_compute.hh @@ -1,312 +1,269 @@ /** * @file dumper_compute.hh * * @author Guillaume Anciaux * * @date creation: Tue Sep 02 2014 * @date last modification: Fri Sep 05 2014 * * @brief Field that map a function to another field * * @section LICENSE * * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ #ifndef __AKANTU_DUMPER_COMPUTE_HH__ #define __AKANTU_DUMPER_COMPUTE_HH__ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "dumper_iohelper.hh" #include "dumper_type_traits.hh" #include "dumper_field.hh" #include "io_helper.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ __BEGIN_AKANTU_DUMPER__ class ComputeFunctorInterface { - public: - virtual ~ComputeFunctorInterface(){}; virtual UInt getDim() = 0; virtual UInt getNbComponent(UInt old_nb_comp) = 0; - }; /* -------------------------------------------------------------------------- */ template class ComputeFunctorOutput : public ComputeFunctorInterface { - public: - ComputeFunctorOutput(){}; virtual ~ComputeFunctorOutput(){}; - }; - /* -------------------------------------------------------------------------- */ - template class ComputeFunctor : public ComputeFunctorOutput { - public: - ComputeFunctor(){}; virtual ~ComputeFunctor(){}; virtual return_type func(const input_type & d, Element global_index) = 0; }; /* -------------------------------------------------------------------------- */ - - template class FieldCompute : public Field { - /* ------------------------------------------------------------------------ */ /* Typedefs */ - /* ------------------------------------------------------------------------ */ - + /* ------------------------------------------------------------------------ */ public: - typedef typename SubFieldCompute::iterator sub_iterator; typedef typename SubFieldCompute::types sub_types; typedef typename sub_types::return_type sub_return_type; typedef _return_type return_type; typedef typename sub_types::data_type data_type; typedef TypeTraits > types; class iterator { public: - iterator(const sub_iterator & it, ComputeFunctor & func) + iterator(const sub_iterator & it, ComputeFunctor & func) : it(it), func(func) {} - + bool operator!=(const iterator & it)const { return it.it != this->it; } iterator operator++() { ++this->it; return *this; } - + UInt currentGlobalIndex(){ return this->it.currentGlobalIndex(); } return_type operator*() { return func.func(*it,it.getCurrentElement()); } Element getCurrentElement(){ return this->it.getCurrentElement(); } - + iohelper::ElemType element_type() { return this->it.element_type(); } + protected: sub_iterator it; ComputeFunctor & func; }; - /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ - public: - FieldCompute(SubFieldCompute & cont, ComputeFunctorInterface & func) :sub_field(cont),func(dynamic_cast &>(func)){ this->checkHomogeneity(); }; virtual void registerToDumper(const std::string & id, iohelper::Dumper & dumper) { dumper.addElemDataField(id, *this); } - /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ - +public: iterator begin() { return iterator(sub_field.begin(), func); } iterator end () { return iterator(sub_field.end(), func); } - UInt getDim() { return func.getDim(); } - - UInt size() { + UInt size() { throw; // return Functor::size(); return 0; } virtual void checkHomogeneity(){this->homogeneous = true;}; iohelper::DataType getDataType() { return iohelper::getDataType(); } - /// get the number of components of the hosted field virtual ElementTypeMap getNbComponents(UInt dim = _all_dimensions, GhostType ghost_type = _not_ghost, ElementKind kind = _ek_not_defined){ - ElementTypeMap nb_components; - const ElementTypeMap & old_nb_components = + const ElementTypeMap & old_nb_components = this->sub_field.getNbComponents(dim,ghost_type,kind); - + ElementTypeMap::type_iterator tit = old_nb_components.firstType(dim,ghost_type,kind); ElementTypeMap::type_iterator end = old_nb_components.lastType(dim,ghost_type,kind); while (tit != end){ UInt nb_comp = old_nb_components(*tit,ghost_type); nb_components(*tit,ghost_type) = func.getNbComponent(nb_comp); ++tit; } - return nb_components; -}; + return nb_components; + }; /// for connection to a FieldCompute inline virtual Field * connect(FieldComputeProxy & proxy); /// for connection to a FieldCompute virtual ComputeFunctorInterface * connect(HomogenizerProxy & proxy); - /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ - public: - SubFieldCompute & sub_field; ComputeFunctor & func; - }; +/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ class FieldComputeProxy { - /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ - public: FieldComputeProxy(ComputeFunctorInterface & func):func(func){}; -public: - - inline static Field * createFieldCompute(Field * field, + inline static Field * createFieldCompute(Field * field, ComputeFunctorInterface & func){ - FieldComputeProxy compute_proxy(func); return field->connect(compute_proxy); } template Field * connectToField(T * ptr){ if (dynamic_cast > *>(&func)){ return this->connectToFunctor >(ptr); } else if (dynamic_cast > *>(&func)){ return this->connectToFunctor >(ptr); } else if (dynamic_cast > *>(&func)){ return this->connectToFunctor >(ptr); } else if (dynamic_cast > *>(&func)){ return this->connectToFunctor >(ptr); } - else throw; } template Field * connectToFunctor(T * ptr){ return new FieldCompute(*ptr,func); } - template Field * connectToFunctor(FieldCompute, return_type2> * ptr){ throw; // return new FieldCompute(*ptr,func); return NULL; } - - template + template Field * connectToFunctor(FieldCompute< - FieldCompute< - FieldCompute< - FieldCompute, - return_type2>, - return_type3>, - return_type4> * ptr){ + FieldCompute< + FieldCompute< + FieldCompute, + return_type2>, + return_type3>, + return_type4> * ptr){ throw; // return new FieldCompute(*ptr,func); return NULL; } - /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ - +public: ComputeFunctorInterface & func; - }; - /* -------------------------------------------------------------------------- */ - /// for connection to a FieldCompute template inline Field * FieldCompute ::connect(FieldComputeProxy & proxy){ - return proxy.connectToField(this); } /* -------------------------------------------------------------------------- */ - - - - - - __END_AKANTU_DUMPER__ __END_AKANTU__ #endif /* __AKANTU_DUMPER_COMPUTE_HH__ */ diff --git a/src/io/dumper/dumper_element_iterator.hh b/src/io/dumper/dumper_element_iterator.hh index ba3d3f3f1..3a22cfd4b 100644 --- a/src/io/dumper/dumper_element_iterator.hh +++ b/src/io/dumper/dumper_element_iterator.hh @@ -1,192 +1,194 @@ /** * @file dumper_element_iterator.hh * * @author Guillaume Anciaux * @author Nicolas Richart * * @date creation: Tue Sep 02 2014 * @date last modification: Wed Sep 03 2014 * * @brief Iterators for elemental fields * * @section LICENSE * * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ #ifndef __AKANTU_DUMPER_ELEMENT_ITERATOR_HH__ #define __AKANTU_DUMPER_ELEMENT_ITERATOR_HH__ /* -------------------------------------------------------------------------- */ #include "element.hh" #include /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ __BEGIN_AKANTU_DUMPER__ /* -------------------------------------------------------------------------- */ template class final_iterator> class element_iterator : public iohelper::iterator, typename types::return_type> { /* ------------------------------------------------------------------------ */ /* Typedefs */ /* ------------------------------------------------------------------------ */ public: typedef typename types::it_type it_type; typedef typename types::field_type field_type; typedef typename types::array_type array_type; typedef typename types::array_iterator array_iterator; typedef final_iterator iterator; public: /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ element_iterator(const field_type & field, const typename field_type::type_iterator & t_it, const typename field_type::type_iterator & t_it_end, const array_iterator & array_it, const array_iterator & array_it_end, const GhostType ghost_type = _not_ghost) : field(field), tit(t_it), tit_end(t_it_end), array_it(array_it), array_it_end(array_it_end), ghost_type(ghost_type) { } /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: bool operator!=(const iterator & it) const { return (ghost_type != it.ghost_type) || (tit != it.tit || (array_it != it.array_it)); } iterator & operator++() { ++array_it; while(array_it == array_it_end && tit != tit_end) { ++tit; if(tit != tit_end) { const array_type & vect = field(*tit, ghost_type); UInt _nb_data_per_elem = getNbDataPerElem(*tit); UInt nb_component = vect.getNbComponent(); UInt size = (vect.getSize() * nb_component) / _nb_data_per_elem; array_it = vect.begin_reinterpret(_nb_data_per_elem,size); array_it_end = vect.end_reinterpret (_nb_data_per_elem,size); } } return *(static_cast(this)); }; ElementType getType() { return *tit; } + iohelper::ElemType element_type() { return getIOHelperType(*tit); } + Element getCurrentElement(){ return Element(*tit,array_it.getCurrentIndex()); } UInt getNbDataPerElem(const ElementType & type) const { return nb_data_per_elem(type,ghost_type); } void setNbDataPerElem(const ElementTypeMap & nb_data){ this->nb_data_per_elem = nb_data; } /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: /// the field to iterate on const field_type & field; /// field iterator typename field_type::type_iterator tit; /// field iterator end typename field_type::type_iterator tit_end; /// array iterator array_iterator array_it; /// internal iterator end array_iterator array_it_end; /// ghost type identification const GhostType ghost_type; /// number of data per element ElementTypeMap nb_data_per_elem; }; /* -------------------------------------------------------------------------- */ template class elemental_field_iterator : public element_iterator { public: /* ------------------------------------------------------------------------ */ /* Typedefs */ /* ------------------------------------------------------------------------ */ typedef element_iterator parent; typedef typename types::it_type it_type; typedef typename types::return_type return_type; typedef typename types::field_type field_type; typedef typename types::array_iterator array_iterator; public: /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ elemental_field_iterator(const field_type & field, const typename field_type::type_iterator & t_it, const typename field_type::type_iterator & t_it_end, const array_iterator & array_it, const array_iterator & array_it_end, const GhostType ghost_type = _not_ghost) : parent(field, t_it, t_it_end, array_it, array_it_end, ghost_type) { } /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ return_type operator*(){ return *this->array_it; } private: }; /* -------------------------------------------------------------------------- */ __END_AKANTU_DUMPER__ __END_AKANTU__ /* -------------------------------------------------------------------------- */ #endif /* __AKANTU_DUMPER_ELEMENT_ITERATOR_HH__ */ diff --git a/src/io/dumper/dumper_element_type.hh b/src/io/dumper/dumper_element_type.hh index a8adb815d..4082fc373 100644 --- a/src/io/dumper/dumper_element_type.hh +++ b/src/io/dumper/dumper_element_type.hh @@ -1,116 +1,107 @@ /** * @file dumper_element_type.hh * * @author Guillaume Anciaux * * @date creation: Tue Sep 02 2014 * @date last modification: Tue Sep 02 2014 * * @brief ElementType Field * * @section LICENSE * * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ __BEGIN_AKANTU__ __BEGIN_AKANTU_DUMPER__ /* -------------------------------------------------------------------------- */ template -class element_type_field_iterator +class element_type_field_iterator : public element_iterator { -public: /* ------------------------------------------------------------------------ */ /* Typedefs */ - /* ------------------------------------------------------------------------ */ + /* ------------------------------------------------------------------------ */ +public: typedef element_iterator parent; typedef typename types::data_type data_type; typedef typename types::return_type return_type; typedef typename types::array_iterator array_iterator; typedef typename types::field_type field_type; -public: - /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ - +public: element_type_field_iterator(const field_type & field, - const typename field_type::type_iterator & t_it, - const typename field_type::type_iterator & t_it_end, - const array_iterator & array_it, - const array_iterator & array_it_end, - const GhostType ghost_type = _not_ghost) : + const typename field_type::type_iterator & t_it, + const typename field_type::type_iterator & t_it_end, + const array_iterator & array_it, + const array_iterator & array_it_end, + const GhostType ghost_type = _not_ghost) : parent(field, t_it, t_it_end, array_it, array_it_end, ghost_type) { } /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ - +public: return_type operator*() { data_type type = getIOHelperType(*this->tit); return return_type(1, type); } }; /* -------------------------------------------------------------------------- */ - - template -class ElementTypeField +class ElementTypeField : public GenericElementalField, - element_type_field_iterator> { -public: + element_type_field_iterator> { + /* ------------------------------------------------------------------------ */ /* Typedefs */ - /* ------------------------------------------------------------------------ */ - + /* ------------------------------------------------------------------------ */ +public: typedef DualType types; typedef element_type_field_iterator iterator; typedef typename types::field_type field_type; typedef GenericElementalField parent; -public: - /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ - +public: ElementTypeField(const field_type & field, UInt spatial_dimension = _all_dimensions, GhostType ghost_type = _not_ghost, ElementKind element_kind = _ek_not_defined) : parent(field, spatial_dimension, ghost_type, element_kind) { this->homogeneous = true; } /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ - +public: UInt getDim() { return 1; } }; - -/* -------------------------------------------------------------------------- */ - __END_AKANTU_DUMPER__ __END_AKANTU__ /* -------------------------------------------------------------------------- */ diff --git a/src/io/dumper/dumper_iohelper.cc b/src/io/dumper/dumper_iohelper.cc index 68be2c65a..3ef20c828 100644 --- a/src/io/dumper/dumper_iohelper.cc +++ b/src/io/dumper/dumper_iohelper.cc @@ -1,301 +1,302 @@ /** * @file dumper_iohelper.cc * * @author Dana Christen * @author David Simon Kammer * @author Guillaume Anciaux * @author Nicolas Richart * * @date creation: Fri Oct 26 2012 * @date last modification: Tue Sep 02 2014 * * @brief implementation of DumperIOHelper * * @section LICENSE * * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include + #include "dumper_iohelper.hh" #include "dumper_elemental_field.hh" #include "dumper_nodal_field.hh" #include "dumper_filtered_connectivity.hh" -#include "dumper_connectivity_field.hh" +//#include "dumper_connectivity_field.hh" #include "dumper_element_type.hh" #include "dumper_variable.hh" #include "mesh.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ DumperIOHelper::DumperIOHelper() : count(0), time_activated(false) {} /* -------------------------------------------------------------------------- */ DumperIOHelper::~DumperIOHelper() { for (Fields::iterator it = fields.begin(); it != fields.end(); ++it) { delete it->second; } delete dumper; } /* -------------------------------------------------------------------------- */ void DumperIOHelper::setParallelContext(bool is_parallel) { UInt whoami = StaticCommunicator::getStaticCommunicator().whoAmI(); UInt nb_proc = StaticCommunicator::getStaticCommunicator().getNbProc(); if(is_parallel) dumper->setParallelContext(whoami, nb_proc); else dumper->setParallelContext(0, 1); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::setDirectory(const std::string & directory) { this->directory = directory; dumper->setPrefix(directory); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::setBaseName(const std::string & basename) { filename = basename; } /* -------------------------------------------------------------------------- */ void DumperIOHelper::setTimeStep(Real time_step) { if(!time_activated) this->dumper->activateTimeDescFiles(time_step); else this->dumper->setTimeStep(time_step); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::dump() { try { dumper->dump(filename, count); } catch (iohelper::IOHelperException & e) { AKANTU_DEBUG_ERROR("I was not able to dump your data with a Dumper: " << e.what()); } ++count; } /* -------------------------------------------------------------------------- */ void DumperIOHelper::dump(UInt step) { this->count = step; this->dump(); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::dump(Real current_time, UInt step) { this->dumper->setCurrentTime(current_time); this->dump(step); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::registerMesh(const Mesh & mesh, UInt spatial_dimension, const GhostType & ghost_type, const ElementKind & element_kind) { -#if defined(AKANTU_COHESIVE_ELEMENT) - if (element_kind == _ek_cohesive) { - registerField("connectivities", - new dumper::CohesiveConnectivityField(mesh.getConnectivities(), - spatial_dimension, - ghost_type)); - } else -#endif +// #if defined(AKANTU_COHESIVE_ELEMENT) +// if (element_kind == _ek_cohesive) { +// registerField("connectivities", +// new dumper::CohesiveConnectivityField(mesh.getConnectivities(), +// spatial_dimension, +// ghost_type)); +// } else +// #endif registerField("connectivities", - new dumper::ElementalField(mesh.getConnectivities(), - spatial_dimension, - ghost_type, - element_kind)); - - registerField("element_type", - new dumper::ElementTypeField<>(mesh.getConnectivities(), - spatial_dimension, - ghost_type, - element_kind)); + new dumper::ElementalField(mesh.getConnectivities(), + spatial_dimension, + ghost_type, + element_kind)); + + // registerField("element_type", + // new dumper::ElementTypeField<>(mesh.getConnectivities(), + // spatial_dimension, + // ghost_type, + // element_kind)); registerField("positions", - new dumper::NodalField(mesh.getNodes())); + new dumper::NodalField(mesh.getNodes())); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::registerFilteredMesh(const Mesh & mesh, const ElementTypeMapArray & elements_filter, const Array & nodes_filter, UInt spatial_dimension, const GhostType & ghost_type, const ElementKind & element_kind) { - - ElementTypeMapArrayFilter * f_connectivities = + + ElementTypeMapArrayFilter * f_connectivities = new ElementTypeMapArrayFilter(mesh.getConnectivities(),elements_filter); this->registerField("connectivities", new dumper::FilteredConnectivityField(*f_connectivities, nodes_filter, spatial_dimension, ghost_type, element_kind)); - this->registerField("element_type", - new dumper::ElementTypeField(*f_connectivities, - spatial_dimension, - ghost_type, - element_kind)); - + // this->registerField("element_type", + // new dumper::ElementTypeField(*f_connectivities, + // spatial_dimension, + // ghost_type, + // element_kind)); + this->registerField("positions",new dumper::NodalField( mesh.getNodes(), 0, 0, &nodes_filter)); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::registerField(const std::string & field_id, dumper::Field * field) { Fields::iterator it = fields.find(field_id); if(it != fields.end()) { - AKANTU_DEBUG_WARNING("The field " << field_id + AKANTU_DEBUG_WARNING("The field " << field_id << " is already registered in this Dumper. Field ignored."); return; } fields[field_id] = field; field->registerToDumper(field_id, *dumper); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::unRegisterField(const std::string & field_id) { Fields::iterator it = fields.find(field_id); if(it == fields.end()) { - AKANTU_DEBUG_WARNING("The field " << field_id + AKANTU_DEBUG_WARNING("The field " << field_id << " is not registered in this Dumper. Nothing to do."); return; } delete it->second; fields.erase(it); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::registerVariable(const std::string & variable_id, dumper::VariableBase * variable) { Variables::iterator it = variables.find(variable_id); if(it != variables.end()) { - AKANTU_DEBUG_WARNING("The Variable " << variable_id + AKANTU_DEBUG_WARNING("The Variable " << variable_id << " is already registered in this Dumper. Variable ignored."); return; } variables[variable_id] = variable; variable->registerToDumper(variable_id, *dumper); } /* -------------------------------------------------------------------------- */ void DumperIOHelper::unRegisterVariable(const std::string & variable_id) { Variables::iterator it = variables.find(variable_id); if(it == variables.end()) { - AKANTU_DEBUG_WARNING("The variable " << variable_id + AKANTU_DEBUG_WARNING("The variable " << variable_id << " is not registered in this Dumper. Nothing to do."); return; } delete it->second; variables.erase(it); } /* -------------------------------------------------------------------------- */ template iohelper::ElemType getIOHelperType() { AKANTU_DEBUG_TO_IMPLEMENT(); return iohelper::MAX_ELEM_TYPE; } template <> iohelper::ElemType getIOHelperType<_segment_2>() { return iohelper::LINE1; } template <> iohelper::ElemType getIOHelperType<_segment_3>() { return iohelper::LINE2; } template <> iohelper::ElemType getIOHelperType<_triangle_3>() { return iohelper::TRIANGLE1; } template <> iohelper::ElemType getIOHelperType<_triangle_6>() { return iohelper::TRIANGLE2; } template <> iohelper::ElemType getIOHelperType<_quadrangle_4>() { return iohelper::QUAD1; } template <> iohelper::ElemType getIOHelperType<_quadrangle_8>() { return iohelper::QUAD2; } template <> iohelper::ElemType getIOHelperType<_tetrahedron_4>() { return iohelper::TETRA1; } template <> iohelper::ElemType getIOHelperType<_tetrahedron_10>() { return iohelper::TETRA2; } template <> iohelper::ElemType getIOHelperType<_hexahedron_8>() { return iohelper::HEX1; } template <> iohelper::ElemType getIOHelperType<_pentahedron_6>() { return iohelper::PRISM1; } #if defined(AKANTU_COHESIVE_ELEMENT) template <> iohelper::ElemType getIOHelperType<_cohesive_2d_4>() { return iohelper::COH2D4; } template <> iohelper::ElemType getIOHelperType<_cohesive_2d_6>() { return iohelper::COH2D6; } template <> iohelper::ElemType getIOHelperType<_cohesive_3d_6>() { return iohelper::COH3D6; } template <> iohelper::ElemType getIOHelperType<_cohesive_3d_12>() { return iohelper::COH3D12; } #endif #if defined(AKANTU_STRUCTURAL_MECHANICS) template <> iohelper::ElemType getIOHelperType<_bernoulli_beam_2>() { return iohelper::BEAM2; } template <> iohelper::ElemType getIOHelperType<_bernoulli_beam_3>() { return iohelper::BEAM3; } #endif /* -------------------------------------------------------------------------- */ iohelper::ElemType getIOHelperType(ElementType type) { iohelper::ElemType ioh_type = iohelper::MAX_ELEM_TYPE; #define GET_IOHELPER_TYPE(type) \ ioh_type = getIOHelperType(); AKANTU_BOOST_ALL_ELEMENT_SWITCH(GET_IOHELPER_TYPE); #undef GET_IOHELPER_TYPE return ioh_type; } /* -------------------------------------------------------------------------- */ __END_AKANTU__ diff --git a/src/io/dumper/dumper_iohelper.hh b/src/io/dumper/dumper_iohelper.hh index 1730a0046..0e1876c56 100644 --- a/src/io/dumper/dumper_iohelper.hh +++ b/src/io/dumper/dumper_iohelper.hh @@ -1,151 +1,157 @@ /** * @file dumper_iohelper.hh * * @author Guillaume Anciaux * @author David Simon Kammer * @author Nicolas Richart * @author Dana Christen * * @date creation: Fri Oct 26 2012 * @date last modification: Wed Sep 03 2014 * * @brief Define the akantu dumper interface for IOhelper dumpers * * @section LICENSE * * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "aka_types.hh" #include "aka_array.hh" #include "element_type_map.hh" /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_DUMPER_IOHELPER_HH__ #define __AKANTU_DUMPER_IOHELPER_HH__ /* -------------------------------------------------------------------------- */ -namespace iohelper { class Dumper; } - +namespace iohelper { + class Dumper; + enum ElemType : unsigned int; +} __BEGIN_AKANTU__ -namespace dumper { class Field; class VariableBase;} +iohelper::ElemType getIOHelperType(ElementType type); + +namespace dumper { + class Field; + class VariableBase; +} class Mesh; class DumperIOHelper { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: DumperIOHelper(); virtual ~DumperIOHelper(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: - /// register a given Mesh for the current dumper virtual void registerMesh(const Mesh & mesh, UInt spatial_dimension = _all_dimensions, const GhostType & ghost_type = _not_ghost, const ElementKind & element_kind = _ek_not_defined); /// register a filtered Mesh (provided filter lists) for the current dumper virtual void registerFilteredMesh(const Mesh & mesh, const ElementTypeMapArray & elements_filter, const Array & nodes_filter, UInt spatial_dimension = _all_dimensions, const GhostType & ghost_type = _not_ghost, const ElementKind & element_kind = _ek_not_defined); /// register a Field object identified by name and provided by pointer void registerField(const std::string & field_id, dumper::Field * field); /// remove the Field identified by name from managed fields void unRegisterField(const std::string & field_id); /// register a VariableBase object identified by name and provided by pointer void registerVariable(const std::string & variable_id, dumper::VariableBase * variable); /// remove a VariableBase identified by name from managed fields void unRegisterVariable(const std::string & variable_id); /// request dump: this calls IOHelper dump routine virtual void dump(); /// request dump: this first set the current step and then calls IOHelper dump routine virtual void dump(UInt step); /// request dump: this first set the current step and current time and then calls IOHelper dump routine virtual void dump(Real current_time, UInt step); /// set the parallel context for IOHeper virtual void setParallelContext(bool is_parallel); /// set the directory where to generate the dumped files virtual void setDirectory(const std::string & directory); /// set the base name (needed by most IOHelper dumpers) virtual void setBaseName(const std::string & basename); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: /// direct access to the iohelper::Dumper object AKANTU_GET_MACRO(Dumper, *dumper, iohelper::Dumper &) /// set the timestep of the iohelper::Dumper void setTimeStep(Real time_step); public: /* ------------------------------------------------------------------------ */ /* Variable wrapper */ template::value> class Variable; /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: /// internal iohelper::Dumper iohelper::Dumper * dumper; typedef std::map Fields; typedef std::map Variables; /// list of registered fields to dump Fields fields; Variables variables; /// dump counter UInt count; /// directory name std::string directory; /// filename prefix std::string filename; /// is time tracking activated in the dumper bool time_activated; }; __END_AKANTU__ #endif /* __AKANTU_DUMPER_IOHELPER_HH__ */ diff --git a/src/io/dumper/dumper_quadrature_points_field.hh b/src/io/dumper/dumper_quadrature_points_field.hh index 5e6326c88..7fa4f0c9d 100644 --- a/src/io/dumper/dumper_quadrature_points_field.hh +++ b/src/io/dumper/dumper_quadrature_points_field.hh @@ -1,127 +1,122 @@ /** * @file dumper_quadrature_points_field.hh * * @author Nicolas Richart * * @date creation: Tue Sep 02 2014 * @date last modification: Tue Sep 02 2014 * * @brief Description of quadrature points fields * * @section LICENSE * * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ #ifndef __AKANTU_DUMPER_IOHELPER_TMPL_QUADRATURE_POINTS_FIELD_HH__ #define __AKANTU_DUMPER_IOHELPER_TMPL_QUADRATURE_POINTS_FIELD_HH__ /* -------------------------------------------------------------------------- */ #include "dumper_elemental_field.hh" -/* -------------------------------------------------------------------------- */ - __BEGIN_AKANTU__ __BEGIN_AKANTU_DUMPER__ - /* -------------------------------------------------------------------------- */ - template -class quadrature_point_iterator - : public element_iterator { +class quadrature_point_iterator + : public element_iterator { /* ------------------------------------------------------------------------ */ /* Typedefs */ - /* ------------------------------------------------------------------------ */ + /* ------------------------------------------------------------------------ */ public: typedef element_iterator parent; - typedef typename types::data_type data_type; - typedef typename types::return_type return_type; - typedef typename types::field_type field_type; - typedef typename types::array_iterator array_iterator; - - /* ------------------------------------------------------------------------ */ - /* Constructors/Destructors */ - /* ------------------------------------------------------------------------ */ + typedef typename types::data_type data_type; + typedef typename types::return_type return_type; + typedef typename types::field_type field_type; + typedef typename types::array_iterator array_iterator; - public: - quadrature_point_iterator(const field_type & field, - const typename field_type::type_iterator & t_it, - const typename field_type::type_iterator & t_it_end, - const array_iterator & array_it, - const array_iterator & array_it_end, - const GhostType ghost_type = _not_ghost) : - parent(field, t_it, t_it_end, array_it, array_it_end, ghost_type) { } - - return_type operator*() { - return *this->array_it; - } - }; + /* ------------------------------------------------------------------------ */ + /* Constructors/Destructors */ + /* ------------------------------------------------------------------------ */ +public: + quadrature_point_iterator(const field_type & field, + const typename field_type::type_iterator & t_it, + const typename field_type::type_iterator & t_it_end, + const array_iterator & array_it, + const array_iterator & array_it_end, + const GhostType ghost_type = _not_ghost) : + parent(field, t_it, t_it_end, array_it, array_it_end, ghost_type) { } + + return_type operator*() { + return *this->array_it; + } +}; /* -------------------------------------------------------------------------- */ /* Fields type description */ /* -------------------------------------------------------------------------- */ template class iterator_type> - class GenericQuadraturePointsField : + class GenericQuadraturePointsField : public GenericElementalField { public: /* ------------------------------------------------------------------------ */ /* Typedefs */ - /* ------------------------------------------------------------------------ */ + /* ------------------------------------------------------------------------ */ typedef iterator_type iterator; typedef typename types::field_type field_type; typedef typename iterator::it_type T; typedef GenericElementalField parent; /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ GenericQuadraturePointsField(const field_type & field, - UInt spatial_dimension = _all_dimensions, - GhostType ghost_type = _not_ghost, - ElementKind element_kind = _ek_not_defined) : + UInt spatial_dimension = _all_dimensions, + GhostType ghost_type = _not_ghost, + ElementKind element_kind = _ek_not_defined) : parent(field, spatial_dimension, ghost_type, element_kind) { } /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ virtual iterator begin() { iterator it = parent::begin(); return it; } virtual iterator end () { iterator it = parent::end(); return it; } }; /* -------------------------------------------------------------------------- */ __END_AKANTU_DUMPER__ __END_AKANTU__ #endif /* __AKANTU_DUMPER_IOHELPER_TMPL_QUADRATURE_POINTS_FIELD_HH__ */ diff --git a/src/mesh/group_manager_inline_impl.cc b/src/mesh/group_manager_inline_impl.cc index 90842d537..939a04505 100644 --- a/src/mesh/group_manager_inline_impl.cc +++ b/src/mesh/group_manager_inline_impl.cc @@ -1,217 +1,215 @@ /** * @file group_manager_inline_impl.cc * * @author Guillaume Anciaux * @author Dana Christen * @author Nicolas Richart * * @date creation: Fri May 03 2013 * @date last modification: Wed Sep 03 2014 * * @brief Stores information relevent to the notion of domain boundary and surfaces. * * @section LICENSE * * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "element_group.hh" #include "dumper_field.hh" #include "element_type_map_filter.hh" #ifdef AKANTU_USE_IOHELPER #include "dumper_nodal_field.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ template class dump_type> dumper::Field * GroupManager -::createElementalField(const ElementTypeMapArray & field, +::createElementalField(const ElementTypeMapArray & field, const std::string & group_name, UInt spatial_dimension, const ElementKind & kind, ElementTypeMap nb_data_per_elem){ - + if (&field == NULL) return NULL; - if (group_name == "all") + if (group_name == "all") return this->createElementalField< dump_type >(field,group_name, spatial_dimension, kind, nb_data_per_elem); else return this->createElementalFilteredField< dump_type >(field,group_name, spatial_dimension, kind, nb_data_per_elem); } /* -------------------------------------------------------------------------- */ template class T2, template class,bool> class dump_type> dumper::Field * GroupManager -::createElementalField(const ElementTypeMapArray & field, +::createElementalField(const ElementTypeMapArray & field, const std::string & group_name, UInt spatial_dimension, const ElementKind & kind, ElementTypeMap nb_data_per_elem){ - + if (&field == NULL) return NULL; - if (group_name == "all") + if (group_name == "all") return this->createElementalField< dump_type >(field, group_name, spatial_dimension, kind, nb_data_per_elem); - else + else return this->createElementalFilteredField< dump_type >(field, group_name, spatial_dimension, kind, nb_data_per_elem); } /* -------------------------------------------------------------------------- */ -template class dump_type> ///< type of InternalMaterialField -dumper::Field * GroupManager::createElementalField(const ElementTypeMapArray & field, +dumper::Field * GroupManager::createElementalField(const ElementTypeMapArray & field, const std::string & group_name, UInt spatial_dimension, const ElementKind & kind, - ElementTypeMap nb_data_per_elem){ + ElementTypeMap nb_data_per_elem) { if (&field == NULL) return NULL; - if (group_name == "all") + if (group_name == "all") return this->createElementalField< dump_type >(field, group_name, spatial_dimension, kind, nb_data_per_elem); - else + else return this->createElementalFilteredField< dump_type >(field, group_name, spatial_dimension, kind, nb_data_per_elem); } /* -------------------------------------------------------------------------- */ template -dumper::Field * GroupManager::createElementalField(const field_type & field, +dumper::Field * GroupManager::createElementalField(const field_type & field, const std::string & group_name, UInt spatial_dimension, const ElementKind & kind, - ElementTypeMap nb_data_per_elem){ - + ElementTypeMap nb_data_per_elem) { if (&field == NULL) return NULL; if (group_name != "all") throw; dumper::Field * dumper = new dump_type(field,spatial_dimension,_not_ghost,kind); dumper->setNbDataPerElem(nb_data_per_elem); return dumper; } /* -------------------------------------------------------------------------- */ template -dumper::Field * GroupManager::createElementalFilteredField(const field_type & field, +dumper::Field * GroupManager::createElementalFilteredField(const field_type & field, const std::string & group_name, UInt spatial_dimension, const ElementKind & kind, - ElementTypeMap nb_data_per_elem){ - + ElementTypeMap nb_data_per_elem) { if (&field == NULL) return NULL; if (group_name == "all") throw; typedef typename field_type::type T; - ElementGroup & group = this->getElementGroup(group_name); + ElementGroup & group = this->getElementGroup(group_name); UInt dim = group.getDimension(); if (dim != spatial_dimension) throw; const ElementTypeMapArray & elemental_filter = group.getElements(); - ElementTypeMapArrayFilter * filtered = + ElementTypeMapArrayFilter * filtered = new ElementTypeMapArrayFilter(field,elemental_filter,nb_data_per_elem); - + dumper::Field * dumper = new dump_type(*filtered,dim,_not_ghost,kind); dumper->setNbDataPerElem(nb_data_per_elem); return dumper; } /* -------------------------------------------------------------------------- */ template class ftype> dumper::Field * GroupManager::createNodalField(const ftype * field, const std::string & group_name, UInt padding_size){ if (field == NULL) return NULL; if (group_name == "all"){ typedef typename dumper::NodalField DumpType; DumpType * dumper = new DumpType(*field, 0, 0, NULL); dumper->setPadding(padding_size); return dumper; } else { - ElementGroup & group = this->getElementGroup(group_name); + ElementGroup & group = this->getElementGroup(group_name); const Array * nodal_filter = &(group.getNodes()); typedef typename dumper::NodalField DumpType; DumpType * dumper = new DumpType(*field, 0, 0, nodal_filter); dumper->setPadding(padding_size); return dumper; } return NULL; } /* -------------------------------------------------------------------------- */ template class ftype> dumper::Field * GroupManager::createStridedNodalField(const ftype * field, const std::string & group_name, - UInt size, UInt stride, + UInt size, UInt stride, UInt padding_size){ if (field == NULL) return NULL; if (group_name == "all"){ typedef typename dumper::NodalField DumpType; DumpType * dumper = new DumpType(*field, size, stride, NULL); dumper->setPadding(padding_size); return dumper; } else { - ElementGroup & group = this->getElementGroup(group_name); + ElementGroup & group = this->getElementGroup(group_name); const Array * nodal_filter = &(group.getNodes()); typedef typename dumper::NodalField DumpType; DumpType * dumper = new DumpType(*field, size, stride, nodal_filter); dumper->setPadding(padding_size); return dumper; } return NULL; } /* -------------------------------------------------------------------------- */ __END_AKANTU__ #endif