diff --git a/extra_packages/traction-at-split-node-contact/README.txt b/extra_packages/traction-at-split-node-contact/README.txt index 8383d544d..b38a0de4b 100644 --- a/extra_packages/traction-at-split-node-contact/README.txt +++ b/extra_packages/traction-at-split-node-contact/README.txt @@ -1,19 +1,26 @@ #=============================================================================== # @file README.txt # # +# @date creation: Tue Dec 02 2014 +# @date last modification: Mon Feb 01 2016 # -# @brief +# @brief kammer # # @section LICENSE # -# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) -# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# Copyright (©) 2015-2018 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 . # #=============================================================================== Short explanation for AkantuSimTools: Using ccmake for compilation, give the path to the build folder of akantu. By putting build_shared_libs on, the library is dynamic. Give a cmake_install_prefix (e.g., ./install). When compiling use: make install (don't forget to create the folder in which you install) diff --git a/extra_packages/traction-at-split-node-contact/package.cmake b/extra_packages/traction-at-split-node-contact/package.cmake index 5be450a70..401cd0ad2 100644 --- a/extra_packages/traction-at-split-node-contact/package.cmake +++ b/extra_packages/traction-at-split-node-contact/package.cmake @@ -1,79 +1,92 @@ #=============================================================================== # @file package.cmake # +# @author Nicolas Richart # +# @date creation: Tue Dec 02 2014 +# @date last modification: Wed Feb 03 2016 # -# @brief +# @brief # # @section LICENSE # -# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Copyright (©) 2015-2018 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 . +# #=============================================================================== - -package_declare(traction-at-split-node-contact +package_declare(traction_at_split_node_contact DESCRIPTION "The super contact of David" DEPENDS iohelper) -package_declare_sources(traction-at-split-node-contact +package_declare_sources(traction_at_split_node_contact common/synchronized_array.cc common/parameter_reader.cc common/manual_restart.cc functions/boundary_functions.cc ntn_contact/ntn_base_contact.cc ntn_contact/ntn_contact.cc ntn_contact/ntrf_contact.cc ntn_contact/mIIasym_contact.cc ntn_contact/ntn_base_friction.cc ntn_contact/friction_regularisations/ntn_fricreg_no_regularisation.cc ntn_contact/friction_regularisations/ntn_fricreg_rubin_ampuero.cc ntn_contact/friction_regularisations/ntn_fricreg_simplified_prakash_clifton.cc ntn_contact/ntn_initiation_function.cc tasn_contact.hh # headers common/synchronized_array.hh common/parameter_reader.hh common/manual_restart.hh functions/boundary_functions.hh functions/node_filter.hh boundary_conditions/force_based_dirichlet.hh boundary_conditions/spring_bc.hh boundary_conditions/inclined_flat_dirichlet.hh ntn_contact/ntn_base_contact.hh ntn_contact/ntn_contact.hh ntn_contact/ntrf_contact.hh ntn_contact/mIIasym_contact.hh ntn_contact/ntn_base_friction.hh ntn_contact/friction_regularisations/ntn_fricreg_no_regularisation.hh ntn_contact/friction_regularisations/ntn_fricreg_rubin_ampuero.hh ntn_contact/friction_regularisations/ntn_fricreg_simplified_prakash_clifton.hh ntn_contact/friction_laws/ntn_friclaw_coulomb.hh ntn_contact/friction_laws/ntn_friclaw_coulomb_tmpl.hh ntn_contact/friction_laws/ntn_friclaw_linear_slip_weakening.hh ntn_contact/friction_laws/ntn_friclaw_linear_slip_weakening_tmpl.hh ntn_contact/friction_laws/ntn_friclaw_linear_slip_weakening_no_healing.hh ntn_contact/friction_laws/ntn_friclaw_linear_slip_weakening_no_healing_tmpl.hh ntn_contact/friction_laws/ntn_friclaw_linear_cohesive.hh ntn_contact/friction_laws/ntn_friclaw_linear_cohesive_tmpl.hh ntn_contact/ntn_friction.hh ntn_contact/ntn_friction_tmpl.hh ntn_contact/ntrf_friction.hh ntn_contact/ntrf_friction_tmpl.hh ntn_contact/ntn_initiation_function.hh # inlines common/synchronized_array_inline_impl.cc ntn_contact/ntn_base_contact_inline_impl.cc ) - - diff --git a/extra_packages/traction-at-split-node-contact/src/boundary_conditions/force_based_dirichlet.hh b/extra_packages/traction-at-split-node-contact/src/boundary_conditions/force_based_dirichlet.hh index b2b4214fa..e57d1a007 100644 --- a/extra_packages/traction-at-split-node-contact/src/boundary_conditions/force_based_dirichlet.hh +++ b/extra_packages/traction-at-split-node-contact/src/boundary_conditions/force_based_dirichlet.hh @@ -1,117 +1,132 @@ /** * @file force_based_dirichlet.hh * * @author Dana Christen * @author David Simon Kammer * + * @date creation: Tue Dec 02 2014 + * @date last modification: Fri Feb 23 2018 * * @brief dirichlet boundary condition that tries * to keep the force at a given value * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 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 __AST_FORCE_BASED_DIRICHLET_HH__ #define __AST_FORCE_BASED_DIRICHLET_HH__ // akantu #include "aka_common.hh" namespace akantu { /* -------------------------------------------------------------------------- */ class ForceBasedDirichlet : public BC::Dirichlet::IncrementValue { protected: typedef const Array * RealArrayPtr; typedef const Array * IntArrayPtr; /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: ForceBasedDirichlet(SolidMechanicsModel & model, BC::Axis ax, Real target_f, Real mass = 0.) : IncrementValue(0., ax), model(model), mass(mass), velocity(0.), target_force(target_f), total_residual(0.) {} virtual ~ForceBasedDirichlet() {} /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: void updateTotalResidual() { SubBoundarySet::iterator it = this->subboundaries.begin(); SubBoundarySet::iterator end = this->subboundaries.end(); this->total_residual = 0.; for (; it != end; ++it) { this->total_residual += integrateResidual(*it, this->model, this->axis); } } virtual Real update() { AKANTU_DEBUG_IN(); this->updateTotalResidual(); Real total_force = this->target_force + this->total_residual; Real a = total_force / this->mass; Real dt = model.getTimeStep(); this->velocity += 0.5 * dt * a; this->value = this->velocity * dt + 0.5 * dt * dt * a; // increment position dx this->velocity += 0.5 * dt * a; AKANTU_DEBUG_OUT(); return this->total_residual; } Real applyYourself() { AKANTU_DEBUG_IN(); Real reaction = this->update(); SubBoundarySet::iterator it = this->subboundaries.begin(); SubBoundarySet::iterator end = this->subboundaries.end(); for (; it != end; ++it) { this->model.applyBC(*this, *it); } AKANTU_DEBUG_OUT(); return reaction; } /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: AKANTU_SET_MACRO(Mass, mass, Real); AKANTU_SET_MACRO(TargetForce, target_force, Real); void insertSubBoundary(const std::string & sb_name) { this->subboundaries.insert(sb_name); } /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ typedef std::set SubBoundarySet; protected: SolidMechanicsModel & model; SubBoundarySet subboundaries; Real mass; Real velocity; Real target_force; Real total_residual; }; } // namespace akantu #endif /* __AST_FORCE_BASED_DIRICHLET_HH__ */ diff --git a/extra_packages/traction-at-split-node-contact/src/boundary_conditions/inclined_flat_dirichlet.hh b/extra_packages/traction-at-split-node-contact/src/boundary_conditions/inclined_flat_dirichlet.hh index cc680d96f..805e9b567 100644 --- a/extra_packages/traction-at-split-node-contact/src/boundary_conditions/inclined_flat_dirichlet.hh +++ b/extra_packages/traction-at-split-node-contact/src/boundary_conditions/inclined_flat_dirichlet.hh @@ -1,66 +1,81 @@ /** * @file inclined_flat_dirichlet.hh * * @author David Simon Kammer * + * @date creation: Fri Jun 18 2010 + * @date last modification: Fri Feb 23 2018 * * @brief inclined dirichlet * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 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 __AST_INCLINED_FLAT_DIRICHLET_HH__ #define __AST_INCLINED_FLAT_DIRICHLET_HH__ // akantu #include "aka_common.hh" namespace akantu { /* -------------------------------------------------------------------------- */ class InclinedFlatDirichlet : public BC::Dirichlet::DirichletFunctor { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: InclinedFlatDirichlet(Real val, BC::Axis ax, BC::Axis incl_ax, Real center_coord, Real tang) : DirichletFunctor(ax), value(val), incl_ax(incl_ax), center_coord(center_coord), tang(tang){}; virtual ~InclinedFlatDirichlet() {} /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: inline void operator()(UInt node, Vector & flags, Vector & primal, const Vector & coord) const { AKANTU_DEBUG_IN(); Real dist = coord(incl_ax) - this->center_coord; flags(axis) = true; primal(axis) = this->value + this->tang * dist; AKANTU_DEBUG_OUT(); } /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: Real value; BC::Axis incl_ax; Real center_coord; Real tang; }; } // namespace akantu #endif /* __AST_INCLINED_FLAT_DIRICHLET_HH__ */ diff --git a/extra_packages/traction-at-split-node-contact/src/boundary_conditions/spring_bc.hh b/extra_packages/traction-at-split-node-contact/src/boundary_conditions/spring_bc.hh index d026e1a40..613be1260 100644 --- a/extra_packages/traction-at-split-node-contact/src/boundary_conditions/spring_bc.hh +++ b/extra_packages/traction-at-split-node-contact/src/boundary_conditions/spring_bc.hh @@ -1,127 +1,142 @@ /** * @file spring_bc.hh * * @author Dana Christen * @author David Simon Kammer * + * @date creation: Tue Dec 02 2014 + * @date last modification: Fri Feb 23 2018 * * @brief spring boundary condition * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 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 __AST_SPRING_BC_HH__ #define __AST_SPRING_BC_HH__ // simtools #include "force_based_dirichlet.hh" namespace akantu { /* -------------------------------------------------------------------------- */ class SpringBC : public ForceBasedDirichlet { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: SpringBC(SolidMechanicsModel & model, BC::Axis ax, Real stiffness, Real mass = 0.) : ForceBasedDirichlet(model, ax, 0., mass), stiffness(stiffness), elongation(0.) {} virtual ~SpringBC() {} /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: virtual Real update() { AKANTU_DEBUG_IN(); this->target_force = -this->stiffness * this->elongation; Real reaction = ForceBasedDirichlet::update(); this->elongation += this->value; AKANTU_DEBUG_OUT(); return reaction; } /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: AKANTU_GET_MACRO(Elongation, elongation, Real); inline void setToEquilibrium() { AKANTU_DEBUG_IN(); this->updateTotalResidual(); this->target_force = -this->total_residual; this->elongation = -this->target_force / this->stiffness; AKANTU_DEBUG_OUT(); } /// change elongation /// dx > 0 -> target_force < 0 inline void incrementElongation(Real dx) { AKANTU_DEBUG_IN(); this->elongation += dx; AKANTU_DEBUG_OUT(); } // friend std::ostream& operator<<(std::ostream& out, const SpringBC & // spring); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: Real stiffness; Real elongation; }; // class SpringBCRestricted : public SpringBC { // public: // SpringBCRestricted(BC::Axis ax, Real target_force, BC::Axis surface_axis, // Real min, Real max) // :SpringBC(ax, target_force), surface_axis(surface_axis), min(min), // max(max) {} // virtual ~SpringBCRestricted() {} // public: // inline void operator()(UInt node, Vector & flags, Vector & // primal, const Vector & coord) const { // if(coord(surface_axis) > min && coord(surface_axis) < max) { // SpringBC::operator()(node, flags, primal, coord); // } // } // private: // BC::Axis surface_axis; // Real min; // Real max; // }; // std::ostream& operator<<(std::ostream& out, const SpringBC & spring) { // out << "Real total_residual: " << *spring.total_residual << std::endl; // out << "Real mass: " << spring.mass << std::endl; // out << "Real k: " << spring.k << std::endl; // out << "Real delta_x: " << spring.delta_x << std::endl; // out << "Real dt: " << spring.dt << std::endl; // out << "Real v: " << spring.v << std::endl; // out << "Real dx: " << spring.dx << std::endl; // out << "Real forcing_vel: " << spring.forcing_vel << std::endl; // return out; // } } // namespace akantu #endif /* __AST_SPRING_BC_HH__ */ diff --git a/extra_packages/traction-at-split-node-contact/src/common/manual_restart.cc b/extra_packages/traction-at-split-node-contact/src/common/manual_restart.cc index 8abdcd9c5..6b104f28c 100644 --- a/extra_packages/traction-at-split-node-contact/src/common/manual_restart.cc +++ b/extra_packages/traction-at-split-node-contact/src/common/manual_restart.cc @@ -1,127 +1,134 @@ /** * @file manual_restart.cc * + * @author Dana Christen * + * @date creation: Tue Dec 02 2014 + * @date last modification: Fri Feb 23 2018 * * @brief * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * - */ - -/** - * @file manual_restart.cc - * @author Dana Christen - * @date May 15, 2013 + * 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 "manual_restart.hh" - -//#include +#include "dof_manager_default.hh" +#include "dof_synchronizer.hh" +/* -------------------------------------------------------------------------- */ #include +/* -------------------------------------------------------------------------- */ using namespace akantu; void dumpArray(const Array & array, const std::string & fname) { std::ofstream outFile; outFile.open(fname.c_str()); outFile.precision(9); outFile.setf(std::ios::scientific); - UInt size = array.getSize(); + UInt size = array.size(); UInt nb_component = array.getNbComponent(); outFile << size << std::endl; outFile << nb_component << std::endl; Array::const_iterator> tit = array.begin(nb_component); Array::const_iterator> tend = array.end(nb_component); for (; tit != tend; ++tit) { for (UInt c = 0; c < nb_component; ++c) { if (c != 0) outFile << " "; outFile << (*tit)(c); } outFile << std::endl; } outFile.close(); } void loadArray(Array & array, const std::string & fname) { std::ifstream inFile; inFile.open(fname.c_str()); inFile.precision(9); inFile.setf(std::ios::scientific); UInt size(0), nb_comp(0); inFile >> size; inFile >> nb_comp; AKANTU_DEBUG_ASSERT(array.getNbComponent() == nb_comp, "BAD NUM OF COMPONENTS"); - AKANTU_DEBUG_ASSERT(array.getSize() == size, + AKANTU_DEBUG_ASSERT(array.size() == size, "loadArray: number of data points in file (" << size << ") does not correspond to array size (" - << array.getSize() << ")!!"); + << array.size() << ")!!"); Array::iterator> tit = array.begin(nb_comp); Array::iterator> tend = array.end(nb_comp); array.resize(size); for (UInt i(0); i < size; ++i, ++tit) { for (UInt c = 0; c < nb_comp; ++c) { inFile >> (*tit)(c); } } inFile.close(); } /* -------------------------------------------------------------------------- */ void loadRestart(akantu::SolidMechanicsModel & model, const std::string & fname, akantu::UInt prank) { const akantu::Mesh & mesh = model.getMesh(); const akantu::UInt spatial_dimension = model.getMesh().getSpatialDimension(); - - const_cast(model.getDOFSynchronizer()) - .initScatterGatherCommunicationScheme(); - + auto & dof_manager = dynamic_cast(model.getDOFManager()); if (prank == 0) { akantu::Array full_reload_array(mesh.getNbGlobalNodes(), spatial_dimension); loadArray(full_reload_array, fname); - model.getDOFSynchronizer().scatter(model.getDisplacement(), 0, - &full_reload_array); + dof_manager.getSynchronizer().scatter(model.getDisplacement(), + full_reload_array); } else { - model.getDOFSynchronizer().scatter(model.getDisplacement(), 0); + dof_manager.getSynchronizer().scatter(model.getDisplacement()); } } /* -------------------------------------------------------------------------- */ void loadRestart(akantu::SolidMechanicsModel & model, const std::string & fname) { loadArray(model.getDisplacement(), fname); } /* -------------------------------------------------------------------------- */ void dumpRestart(akantu::SolidMechanicsModel & model, const std::string & fname, akantu::UInt prank) { const akantu::Mesh & mesh = model.getMesh(); const akantu::UInt spatial_dimension = model.getMesh().getSpatialDimension(); - - const_cast(model.getDOFSynchronizer()) - .initScatterGatherCommunicationScheme(); + auto & dof_manager = dynamic_cast(model.getDOFManager()); if (prank == 0) { akantu::Array full_array(mesh.getNbGlobalNodes(), spatial_dimension); - model.getDOFSynchronizer().gather(model.getDisplacement(), 0, &full_array); + dof_manager.getSynchronizer().gather(model.getDisplacement(), full_array); dumpArray(full_array, fname); } else { - model.getDOFSynchronizer().gather(model.getDisplacement(), 0); + dof_manager.getSynchronizer().gather(model.getDisplacement()); } } /* -------------------------------------------------------------------------- */ void dumpRestart(akantu::SolidMechanicsModel & model, const std::string & fname) { dumpArray(model.getDisplacement(), fname); } diff --git a/extra_packages/traction-at-split-node-contact/src/common/manual_restart.hh b/extra_packages/traction-at-split-node-contact/src/common/manual_restart.hh index be9d73465..989cede16 100644 --- a/extra_packages/traction-at-split-node-contact/src/common/manual_restart.hh +++ b/extra_packages/traction-at-split-node-contact/src/common/manual_restart.hh @@ -1,36 +1,52 @@ /** * @file manual_restart.hh * + * @author David Simon Kammer * + * @date creation: Tue Dec 02 2014 + * @date last modification: Fri Feb 23 2018 * * @brief * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 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 . + * */ /** * @file manual_restart.hh * @author Dana Christen * @date May 15, 2013 */ /* -------------------------------------------------------------------------- */ #include "aka_array.hh" #include "solid_mechanics_model.hh" void dumpArray(const akantu::Array & array, const std::string & fname); void loadArray(akantu::Array & array, const std::string & fname); void loadRestart(akantu::SolidMechanicsModel & model, const std::string & fname, akantu::UInt prank); void loadRestart(akantu::SolidMechanicsModel & model, const std::string & fname); void dumpRestart(akantu::SolidMechanicsModel & model, const std::string & fname, akantu::UInt prank); void dumpRestart(akantu::SolidMechanicsModel & model, const std::string & fname); diff --git a/extra_packages/traction-at-split-node-contact/src/common/parameter_reader.cc b/extra_packages/traction-at-split-node-contact/src/common/parameter_reader.cc index fc2515008..5532c7dfe 100644 --- a/extra_packages/traction-at-split-node-contact/src/common/parameter_reader.cc +++ b/extra_packages/traction-at-split-node-contact/src/common/parameter_reader.cc @@ -1,441 +1,456 @@ /** * @file parameter_reader.cc * * @author David Simon Kammer * + * @date creation: Tue Dec 02 2014 + * @date last modification: Fri Feb 23 2018 * * @brief implementation of parameter reader * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 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 . + * */ /* -------------------------------------------------------------------------- */ // std #include #include #include #include // simtools #include "parameter_reader.hh" namespace akantu { /* -------------------------------------------------------------------------- */ ParameterReader::ParameterReader() : data_types(), element_type_data(), string_data(), int_data(), uint_data(), real_data(), bool_data() { AKANTU_DEBUG_IN(); // setup of types of element data_types.insert("elementtype"); data_types.insert("string"); data_types.insert("uint"); data_types.insert("int"); data_types.insert("real"); data_types.insert("bool"); // data_types.insert("surface"); // define conversion maps _input_to_akantu_element_types["_segment_2"] = akantu::_segment_2; _input_to_akantu_element_types["_segment_3"] = akantu::_segment_3; _input_to_akantu_element_types["_triangle_3"] = akantu::_triangle_3; _input_to_akantu_element_types["_triangle_6"] = akantu::_triangle_6; _input_to_akantu_element_types["_tetrahedron_4"] = akantu::_tetrahedron_4; _input_to_akantu_element_types["_tetrahedron_10"] = akantu::_tetrahedron_10; _input_to_akantu_element_types["_quadrangle_4"] = akantu::_quadrangle_4; _input_to_akantu_element_types["_quadrangle_8"] = akantu::_quadrangle_8; _input_to_akantu_element_types["_hexahedron_8"] = akantu::_hexahedron_8; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void ParameterReader::readInputFile(std::string file_name) { AKANTU_DEBUG_IN(); char comment_char = '#'; char equal_char = '='; // open a file called file name std::ifstream infile; infile.open(file_name.c_str()); if (!infile.good()) { std::cerr << "Cannot open file " << file_name << "!!!" << std::endl; exit(EXIT_FAILURE); } std::string line; std::string clean_line; while (infile.good()) { getline(infile, line); clean_line = line; // take out comments size_t found_comment; found_comment = line.find_first_of(comment_char); if (found_comment != std::string::npos) clean_line = line.substr(0, found_comment); if (clean_line.empty()) continue; std::stringstream sstr(clean_line); // check if data type exists std::string type; sstr >> type; std::transform(type.begin(), type.end(), type.begin(), ::tolower); if (this->data_types.find(type) == this->data_types.end()) { std::cerr << " *** WARNING *** Data type " << type << " does not exist" << " in this input data structure. Ignore line: "; std::cerr << clean_line << std::endl; continue; } std::string keyword; std::string equal; std::string value; // get keyword sstr >> keyword; size_t equal_p = keyword.find_first_of(equal_char); if (equal_p != std::string::npos) { equal = keyword.substr(equal_p, std::string::npos); keyword = keyword.substr(0, equal_p); } // get equal if (equal.empty()) sstr >> equal; if (equal.length() != 1) { value = equal.substr(1, std::string::npos); equal = equal[0]; } if (equal[0] != equal_char) { std::cerr << " *** WARNING *** Unrespected convention! Ignore line: "; std::cerr << clean_line << std::endl; continue; } // get value if (value.empty()) sstr >> value; // no value if (value.empty()) { std::cerr << " *** WARNING *** No value given! Ignore line: "; std::cerr << clean_line << std::endl; continue; } // put value in map std::stringstream convert(value); if (type.compare("elementtype") == 0) { std::map::const_iterator it; it = this->_input_to_akantu_element_types.find(value); if (it != this->_input_to_akantu_element_types.end()) this->element_type_data.insert(std::make_pair(keyword, it->second)); else { std::cerr << " *** WARNING *** ElementType " << value << " does not exist. Ignore line: "; std::cerr << clean_line << std::endl; continue; } } else if (type.compare("string") == 0) { this->string_data.insert(std::make_pair(keyword, value)); } /* else if (type.compare("surface") == 0) { //Surface surf; UInt surf; convert >> surf; //this->surface_data.insert(std::make_pair(keyword,surf)); this->uint_data.insert(std::make_pair(keyword,surf)); } */ else if (type.compare("int") == 0) { Int i; convert >> i; this->int_data.insert(std::make_pair(keyword, i)); } else if (type.compare("uint") == 0) { UInt i; convert >> i; this->uint_data.insert(std::make_pair(keyword, i)); } else if (type.compare("real") == 0) { Real r; convert >> r; this->real_data.insert(std::make_pair(keyword, r)); } else if (type.compare("bool") == 0) { std::transform(value.begin(), value.end(), value.begin(), ::tolower); bool b; if (value.compare("true") == 0) b = true; else if (value.compare("false") == 0) b = false; else { std::cerr << " *** WARNING *** boolean cannot be " << value << ". Ignore line: "; std::cerr << clean_line << std::endl; continue; } this->bool_data.insert(std::make_pair(keyword, b)); } else { std::cerr << " *** ERROR *** Could not add data to InputData for line: "; std::cerr << clean_line << std::endl; continue; exit(EXIT_FAILURE); } } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void ParameterReader::writeInputFile(std::string file_name) const { AKANTU_DEBUG_IN(); // open file to write input information std::ofstream outfile; outfile.open(file_name.c_str()); // element type for (std::map::const_iterator it = element_type_data.begin(); it != element_type_data.end(); ++it) { for (std::map::const_iterator et = _input_to_akantu_element_types.begin(); et != _input_to_akantu_element_types.end(); ++et) { if (it->second == et->second) { outfile << "ElementType " << it->first << " = " << et->first << std::endl; continue; } } } // string for (std::map::const_iterator it = string_data.begin(); it != string_data.end(); ++it) outfile << "string " << it->first << " = " << it->second << std::endl; // Surface /* for (std::map::const_iterator it = surface_data.begin(); it != surface_data.end(); ++it) outfile << "Surface " << it->first << " = " << it->second << std::endl; */ // Int for (std::map::const_iterator it = int_data.begin(); it != int_data.end(); ++it) outfile << "Int " << it->first << " = " << it->second << std::endl; // UInt for (std::map::const_iterator it = uint_data.begin(); it != uint_data.end(); ++it) outfile << "UInt " << it->first << " = " << it->second << std::endl; // Real for (std::map::const_iterator it = real_data.begin(); it != real_data.end(); ++it) outfile << "Real " << it->first << " = " << it->second << std::endl; // Bool for (std::map::const_iterator it = bool_data.begin(); it != bool_data.end(); ++it) { std::string b = "false"; if (it->second) b = "true"; outfile << "bool " << it->first << " = " << b << std::endl; } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template <> akantu::UInt ParameterReader::get(std::string key) const { std::map::const_iterator it; it = this->uint_data.find(key); // if not in map if (it == this->uint_data.end()) { std::cerr << " *** ERROR *** This data was not in input file. " << "You need the following line in your input file: "; std::cerr << "UInt " << key << " = ???" << std::endl; exit(EXIT_FAILURE); } else return it->second; } /* -------------------------------------------------------------------------- */ template <> akantu::ElementType ParameterReader::get(std::string key) const { std::map::const_iterator it; it = this->element_type_data.find(key); // if not in map if (it == this->element_type_data.end()) { std::cerr << " *** ERROR *** This data was not in input file. " << "You need the following line in your input file: "; std::cerr << "ElementType " << key << " = ???" << std::endl; exit(EXIT_FAILURE); } else return it->second; } /* -------------------------------------------------------------------------- */ template <> std::string ParameterReader::get(std::string key) const { std::map::const_iterator it; it = this->string_data.find(key); // if not in map if (it == this->string_data.end()) { std::cerr << " *** ERROR *** This data was not in input file. " << "You need the following line in your input file: "; std::cerr << "string " << key << " = ???" << std::endl; exit(EXIT_FAILURE); } else return it->second; } /* -------------------------------------------------------------------------- */ /* template<> akantu::Surface ParameterData::get(std::string key) const { std::map::const_iterator it; it = this->surface_data.find(key); // if not in map if (it == this->surface_data.end()) { std::cerr << " *** ERROR *** This data was not in input file. " << "You need the following line in your input file: "; std::cerr << "Surface " << key << " = ???" << std::endl; exit(EXIT_FAILURE); } else return it->second; } */ /* -------------------------------------------------------------------------- */ template <> akantu::Int ParameterReader::get(std::string key) const { std::map::const_iterator it; it = this->int_data.find(key); // if not in map if (it == this->int_data.end()) { std::cerr << " *** ERROR *** This data was not in input file. " << "You need the following line in your input file: "; std::cerr << "Int " << key << " = ???" << std::endl; exit(EXIT_FAILURE); } else return it->second; } /* -------------------------------------------------------------------------- */ template <> akantu::Real ParameterReader::get(std::string key) const { std::map::const_iterator it; it = this->real_data.find(key); // if not in map if (it == this->real_data.end()) { std::cerr << " *** ERROR *** This data was not in input file. " << "You need the following line in your input file: "; std::cerr << "Real " << key << " = ???" << std::endl; exit(EXIT_FAILURE); } else return it->second; } /* -------------------------------------------------------------------------- */ template <> bool ParameterReader::get(std::string key) const { std::map::const_iterator it; it = this->bool_data.find(key); // if not in map if (it == this->bool_data.end()) { std::cerr << " *** ERROR *** This data was not in input file. " << "You need the following line in your input file: "; std::cerr << "bool " << key << " = ???" << std::endl; exit(EXIT_FAILURE); } else return it->second; } /* -------------------------------------------------------------------------- */ template <> bool ParameterReader::has(std::string key) const { std::map::const_iterator it; it = this->bool_data.find(key); return (it != this->bool_data.end()); } template <> bool ParameterReader::has(std::string key) const { std::map::const_iterator it; it = this->string_data.find(key); return (it != this->string_data.end()); } template <> bool ParameterReader::has(std::string key) const { std::map::const_iterator it; it = this->int_data.find(key); return (it != this->int_data.end()); } template <> bool ParameterReader::has(std::string key) const { std::map::const_iterator it; it = this->uint_data.find(key); return (it != this->uint_data.end()); } template <> bool ParameterReader::has(std::string key) const { std::map::const_iterator it; it = this->real_data.find(key); return (it != this->real_data.end()); } /* -------------------------------------------------------------------------- */ void ParameterReader::printself(std::ostream & stream, int indent) const { AKANTU_DEBUG_IN(); std::string space; for (Int i = 0; i < indent; i++, space += AKANTU_INDENT) ; stream << space << "ParameterReader [" << std::endl; /* stream << space << this->element_type_data << std::endl; stream << space << this->string_data << std::endl; stream << space << this->surface_data << std::endl; stream << space << this->int_data << std::endl; stream << space << this->uint_data << std::endl; stream << space << this->real_data << std::endl; stream << space << this->bool_data << std::endl; */ stream << space << "]" << std::endl; AKANTU_DEBUG_OUT(); } } // namespace akantu diff --git a/extra_packages/traction-at-split-node-contact/src/common/parameter_reader.hh b/extra_packages/traction-at-split-node-contact/src/common/parameter_reader.hh index f1e39a68d..0583e6006 100644 --- a/extra_packages/traction-at-split-node-contact/src/common/parameter_reader.hh +++ b/extra_packages/traction-at-split-node-contact/src/common/parameter_reader.hh @@ -1,95 +1,110 @@ /** * @file parameter_reader.hh * * @author David Simon Kammer * + * @date creation: Fri Jun 18 2010 + * @date last modification: Fri Feb 23 2018 * * @brief for simulations to read parameters from an input file * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 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 __AST_PARAMETER_READER_HH__ #define __AST_PARAMETER_READER_HH__ /* -------------------------------------------------------------------------- */ // std #include #include // akantu #include "aka_common.hh" namespace akantu { /* -------------------------------------------------------------------------- */ class ParameterReader { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: ParameterReader(); virtual ~ParameterReader(){}; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// read input file void readInputFile(std::string file_name); /// write input file void writeInputFile(std::string file_name) const; /// function to print the contain of the class virtual void printself(std::ostream & stream, int indent = 0) const; /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: /// template T get(std::string key) const; template bool has(std::string key) const; /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: /// type of data available std::set data_types; /// data std::map element_type_data; std::map string_data; std::map int_data; std::map uint_data; std::map real_data; std::map bool_data; /// convert string to element type std::map _input_to_akantu_element_types; }; /* -------------------------------------------------------------------------- */ /* inline functions */ /* -------------------------------------------------------------------------- */ //#include "parameter_reader_inline_impl.cc" /// standard output stream operator inline std::ostream & operator<<(std::ostream & stream, const ParameterReader & _this) { _this.printself(stream); return stream; } } // namespace akantu #endif /* __AST_PARAMETER_READER_HH__ */ diff --git a/extra_packages/traction-at-split-node-contact/src/common/synchronized_array.cc b/extra_packages/traction-at-split-node-contact/src/common/synchronized_array.cc index f2d0bd016..26e97e945 100644 --- a/extra_packages/traction-at-split-node-contact/src/common/synchronized_array.cc +++ b/extra_packages/traction-at-split-node-contact/src/common/synchronized_array.cc @@ -1,230 +1,245 @@ /** * @file synchronized_array.cc * * @author David Simon Kammer * + * @date creation: Tue Dec 02 2014 + * @date last modification: Fri Feb 23 2018 * * @brief implementation of synchronized array function * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 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 . + * */ /* -------------------------------------------------------------------------- */ // std #include #include // simtools #include "synchronized_array.hh" namespace akantu { /* -------------------------------------------------------------------------- */ template SynchronizedArray::SynchronizedArray( UInt size, UInt nb_component, SynchronizedArray::const_reference value, const ID & id, SynchronizedArray::const_reference default_value, const std::string restart_name) : SynchronizedArrayBase(), Array(size, nb_component, value, id), default_value(default_value), restart_name(restart_name), deleted_elements(0), nb_added_elements(size), depending_arrays(0) { AKANTU_DEBUG_IN(); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template void SynchronizedArray::syncElements(SyncChoice sync_choice) { AKANTU_DEBUG_IN(); if (sync_choice == _deleted) { std::vector::iterator it; for (it = depending_arrays.begin(); it != depending_arrays.end(); ++it) { UInt vec_size = (*it)->syncDeletedElements(this->deleted_elements); - AKANTU_DEBUG_ASSERT(vec_size == this->size, + AKANTU_DEBUG_ASSERT(vec_size == this->size_, "Synchronized arrays do not have the same length" << "(may be a double synchronization)"); } this->deleted_elements.clear(); } else if (sync_choice == _added) { std::vector::iterator it; for (it = depending_arrays.begin(); it != depending_arrays.end(); ++it) { UInt vec_size = (*it)->syncAddedElements(this->nb_added_elements); - AKANTU_DEBUG_ASSERT(vec_size == this->size, + AKANTU_DEBUG_ASSERT(vec_size == this->size_, "Synchronized arrays do not have the same length" << "(may be a double synchronization)"); } this->nb_added_elements = 0; } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template UInt SynchronizedArray::syncDeletedElements( std::vector & del_elements) { AKANTU_DEBUG_IN(); AKANTU_DEBUG_ASSERT( nb_added_elements == 0 && deleted_elements.size() == 0, "Cannot sync with a SynchronizedArray if it has already been modified"); std::vector::const_iterator it; for (it = del_elements.begin(); it != del_elements.end(); ++it) { erase(*it); } syncElements(_deleted); AKANTU_DEBUG_OUT(); - return this->size; + return this->size_; } /* -------------------------------------------------------------------------- */ template UInt SynchronizedArray::syncAddedElements(UInt nb_add_elements) { AKANTU_DEBUG_IN(); AKANTU_DEBUG_ASSERT( nb_added_elements == 0 && deleted_elements.size() == 0, "Cannot sync with a SynchronizedArray if it has already been modified"); for (UInt i = 0; i < nb_add_elements; ++i) { push_back(this->default_value); } syncElements(_added); AKANTU_DEBUG_OUT(); - return this->size; + return this->size_; } /* -------------------------------------------------------------------------- */ template void SynchronizedArray::registerDependingArray( SynchronizedArrayBase & array) { AKANTU_DEBUG_IN(); this->depending_arrays.push_back(&array); - array.syncAddedElements(this->size); + array.syncAddedElements(this->size_); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template void SynchronizedArray::printself(std::ostream & stream, int indent) const { AKANTU_DEBUG_IN(); std::string space; for (Int i = 0; i < indent; i++, space += AKANTU_INDENT) ; stream << space << "SynchronizedArray<" << debug::demangle(typeid(T).name()) << "> [" << std::endl; stream << space << " + default_value : " << this->default_value << std::endl; stream << space << " + nb_added_elements : " << this->nb_added_elements << std::endl; stream << space << " + deleted_elements : "; for (std::vector::const_iterator it = this->deleted_elements.begin(); it != this->deleted_elements.end(); ++it) stream << *it << " "; stream << std::endl; stream << space << " + depending_arrays : "; for (std::vector::const_iterator it = this->depending_arrays.begin(); it != this->depending_arrays.end(); ++it) stream << (*it)->getID() << " "; stream << std::endl; Array::printself(stream, indent + 1); stream << space << "]" << std::endl; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template void SynchronizedArray::dumpRestartFile(std::string file_name) const { AKANTU_DEBUG_IN(); AKANTU_DEBUG_ASSERT( nb_added_elements == 0 && deleted_elements.size() == 0, "Restart File for SynchronizedArray " << this->id << " should not be dumped as it is not synchronized yet"); std::stringstream name; name << file_name << "-" << this->restart_name << ".rs"; std::ofstream out_restart; out_restart.open(name.str().c_str()); - out_restart << this->size << " " << this->nb_component << std::endl; - Real size_comp = this->size * this->nb_component; + out_restart << this->size_ << " " << this->nb_component << std::endl; + Real size_comp = this->size_ * this->nb_component; for (UInt i = 0; i < size_comp; ++i) out_restart << std::setprecision(12) << this->values[i] << " "; // out_restart << std::hex << std::setprecision(12) << this->values[i] << " // "; out_restart << std::endl; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template void SynchronizedArray::readRestartFile(std::string file_name) { AKANTU_DEBUG_IN(); AKANTU_DEBUG_ASSERT( nb_added_elements == 0 && deleted_elements.size() == 0, "Restart File for SynchronizedArray " << this->id << " should not be read as it is not synchronized yet"); std::stringstream name; name << file_name << "-" << this->restart_name << ".rs"; std::ifstream infile; infile.open(name.str().c_str()); std::string line; // get size and nb_component info AKANTU_DEBUG_ASSERT(infile.good(), "Could not read restart file for " << "SynchronizedArray " << this->id); getline(infile, line); std::stringstream size_comp(line); - size_comp >> this->size; + size_comp >> this->size_; size_comp >> this->nb_component; // get elements in array getline(infile, line); std::stringstream data(line); - for (UInt i = 0; i < this->size * this->nb_component; ++i) { + for (UInt i = 0; i < this->size_ * this->nb_component; ++i) { AKANTU_DEBUG_ASSERT( !data.eof(), "Read SynchronizedArray " << this->id << " got to the end of the file before having read all data!"); data >> this->values[i]; // data >> std::hex >> this->values[i]; } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template class SynchronizedArray; template class SynchronizedArray; template class SynchronizedArray; template class SynchronizedArray; } // namespace akantu diff --git a/extra_packages/traction-at-split-node-contact/src/common/synchronized_array.hh b/extra_packages/traction-at-split-node-contact/src/common/synchronized_array.hh index c3bb398db..7ec3c68b8 100644 --- a/extra_packages/traction-at-split-node-contact/src/common/synchronized_array.hh +++ b/extra_packages/traction-at-split-node-contact/src/common/synchronized_array.hh @@ -1,190 +1,204 @@ /** * @file synchronized_array.hh * * @author David Simon Kammer * + * @date creation: Tue Dec 02 2014 + * @date last modification: Fri Feb 23 2018 * * @brief synchronized array: a array can be registered to another (hereafter * called top) array. If an element is added to or removed from the top array, * the registered array removes or adds at the same position an element. The two * arrays stay therefore synchronized. * * @section LICENSE * - * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Copyright (©) 2015-2018 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 __AST_SYNCHRONIZED_ARRAY_HH__ #define __AST_SYNCHRONIZED_ARRAY_HH__ /* -------------------------------------------------------------------------- */ // std #include // akantu #include "aka_array.hh" namespace akantu { /* -------------------------------------------------------------------------- */ enum SyncChoice { _added, _deleted }; /* -------------------------------------------------------------------------- */ class SynchronizedArrayBase { public: SynchronizedArrayBase(){}; ~SynchronizedArrayBase(){}; virtual ID getID() const { return "call should be virtual"; }; virtual UInt syncDeletedElements(std::vector & delete_el) = 0; virtual UInt syncAddedElements(UInt nb_added_el) = 0; }; /* -------------------------------------------------------------------------- */ template class SynchronizedArray : public SynchronizedArrayBase, protected Array { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: typedef typename Array::value_type value_type; typedef typename Array::reference reference; typedef typename Array::pointer_type pointer_type; typedef typename Array::const_reference const_reference; SynchronizedArray(UInt size, UInt nb_component, const_reference value, const ID & id, const_reference default_value, const std::string restart_name); virtual ~SynchronizedArray(){}; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// push_back - inline void push_back(const_reference value); - inline void push_back(const value_type new_element[]); + template inline void push_back(P && value); /// erase inline void erase(UInt i); // template // inline void erase(const iterator & it); /// synchronize elements void syncElements(SyncChoice sync_choice); /// dump restart file void dumpRestartFile(std::string file_name) const; /// read restart file void readRestartFile(std::string file_name); /// register depending array void registerDependingArray(SynchronizedArrayBase & array); /// function to print the contain of the class virtual void printself(std::ostream & stream, int indent = 0) const; /// find position of element Int find(const T & elem) const { return Array::find(elem); }; /// set values to zero inline void clear() { Array::clear(); }; // inline void clear() { memset(values, 0, size*nb_component*sizeof(T)); }; /// set all entries of the array to the value t /// @param t value to fill the array with inline void set(T t) { Array::set(t); } /// set template