diff --git a/examples/explicit/explicit_dynamic.cc b/examples/explicit/explicit_dynamic.cc index e640a7344..c03506e49 100644 --- a/examples/explicit/explicit_dynamic.cc +++ b/examples/explicit/explicit_dynamic.cc @@ -1,106 +1,113 @@ /** * @file explicit_dynamic.cc * * @author Seyedeh Mohadeseh Taheri Mousavi * * @date creation: Sun Jul 12 2015 * @date last modification: Mon Jan 18 2016 * * @brief This code refers to the explicit dynamic example from the user manual * * @section LICENSE * * Copyright (©) 2015 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 "solid_mechanics_model.hh" /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char * argv[]) { initialize("material.dat", argc, argv); const UInt spatial_dimension = 3; const Real pulse_width = 2.; const Real A = 0.01; Real time_step; Real time_factor = 0.8; UInt max_steps = 1000; Mesh mesh(spatial_dimension); - mesh.read("bar.msh"); + if(Communicator::getStaticCommunicator().whoAmI() == 0) + mesh.read("bar.msh"); + + mesh.distribute(); + + mesh.makePeriodic(_x); + mesh.makePeriodic(_y); + mesh.makePeriodic(_z); SolidMechanicsModel model(mesh); /// model initialization model.initFull(_analysis_method = _explicit_lumped_mass); time_step = model.getStableTimeStep(); std::cout << "Time Step = " << time_step * time_factor << "s (" << time_step << "s)" << std::endl; model.setTimeStep(time_step * time_factor); /// boundary and initial conditions Array & displacement = model.getDisplacement(); const Array & nodes = mesh.getNodes(); for (UInt n = 0; n < mesh.getNbNodes(); ++n) { - Real x = nodes(n); + Real x = nodes(n) - 2; // Sinus * Gaussian Real L = pulse_width; Real k = 0.1 * 2 * M_PI * 3 / L; displacement(n) = A * sin(k * x) * exp(-(k * x) * (k * x) / (L * L)); } std::ofstream energy; energy.open("energy.csv"); energy << "id,rtime,epot,ekin,tot" << std::endl; model.setBaseName("explicit_dynamic"); model.addDumpField("displacement"); model.addDumpField("velocity"); model.addDumpField("acceleration"); model.addDumpField("stress"); model.dump(); for (UInt s = 1; s <= max_steps; ++s) { model.solveStep(); Real epot = model.getEnergy("potential"); Real ekin = model.getEnergy("kinetic"); energy << s << "," << s * time_step << "," << epot << "," << ekin << "," << epot + ekin << "," << std::endl; if (s % 10 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; model.dump(); } energy.close(); finalize(); return EXIT_SUCCESS; } diff --git a/src/common/aka_array.cc b/src/common/aka_array.cc index 9c273ed17..b31c3248d 100644 --- a/src/common/aka_array.cc +++ b/src/common/aka_array.cc @@ -1,123 +1,117 @@ /** * @file aka_array.cc * * @author Nicolas Richart * * @date creation: Fri Jun 18 2010 * @date last modification: Tue Feb 20 2018 * * @brief Implementation of akantu::Array * * @section LICENSE * * Copyright (©) 2010-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 . * */ /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ #include "aka_array.hh" #include "aka_common.hh" namespace akantu { /* -------------------------------------------------------------------------- */ /* Functions ArrayBase */ /* -------------------------------------------------------------------------- */ -ArrayBase::ArrayBase(ID id) - : id(std::move(id)), allocated_size(0), size_(0), nb_component(1), - size_of_type(0) {} - -/* -------------------------------------------------------------------------- */ -ArrayBase::~ArrayBase() = default; /* -------------------------------------------------------------------------- */ void ArrayBase::printself(std::ostream & stream, int indent) const { std::string space; for (Int i = 0; i < indent; i++, space += AKANTU_INDENT) ; stream << space << "ArrayBase [" << std::endl; stream << space << " + size : " << size_ << std::endl; stream << space << " + nb component : " << nb_component << std::endl; stream << space << " + allocated size : " << allocated_size << std::endl; Real mem_size = (allocated_size * nb_component * size_of_type) / 1024.; stream << space << " + size of type : " << size_of_type << "B" << std::endl; stream << space << " + memory allocated : " << mem_size << "kB" << std::endl; stream << space << "]" << std::endl; } /* -------------------------------------------------------------------------- */ template <> UInt Array::find(const Real & elem) const { AKANTU_DEBUG_IN(); Real epsilon = std::numeric_limits::epsilon(); auto it = std::find_if(begin(), end(), [&elem, &epsilon](auto && a) { return std::abs(a - elem) <= epsilon; }); AKANTU_DEBUG_OUT(); return (it != end()) ? end() - it : UInt(-1); } /* -------------------------------------------------------------------------- */ template <> Array & Array::operator*=(__attribute__((unused)) const ElementType & alpha) { AKANTU_TO_IMPLEMENT(); return *this; } template <> Array & Array:: operator-=(__attribute__((unused)) const Array & vect) { AKANTU_TO_IMPLEMENT(); return *this; } template <> Array & Array:: operator+=(__attribute__((unused)) const Array & vect) { AKANTU_TO_IMPLEMENT(); return *this; } template <> Array & Array::operator*=(__attribute__((unused)) const char & alpha) { AKANTU_TO_IMPLEMENT(); return *this; } template <> Array & Array::operator-=(__attribute__((unused)) const Array & vect) { AKANTU_TO_IMPLEMENT(); return *this; } template <> Array & Array::operator+=(__attribute__((unused)) const Array & vect) { AKANTU_TO_IMPLEMENT(); return *this; } } // namespace akantu diff --git a/src/common/aka_array.hh b/src/common/aka_array.hh index a75bd18ed..2a36fd1e7 100644 --- a/src/common/aka_array.hh +++ b/src/common/aka_array.hh @@ -1,371 +1,381 @@ /** * @file aka_array.hh * * @author Till Junge * @author Nicolas Richart * * @date creation: Fri Jun 18 2010 * @date last modification: Tue Jan 16 2018 * * @brief Array container for Akantu * This container differs from the std::vector from the fact it as 2 dimensions * a main dimension and the size stored per entries * * @section LICENSE * * Copyright (©) 2010-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 __AKANTU_VECTOR_HH__ #define __AKANTU_VECTOR_HH__ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ namespace akantu { /// class that afford to store vectors in static memory class ArrayBase { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: - explicit ArrayBase(ID id = ""); + explicit ArrayBase(ID id = "") : id(std::move(id)) {} + + ArrayBase(const ArrayBase & other) = default; + ArrayBase(ArrayBase && other) = default; + + ArrayBase & operator=(const ArrayBase & other) = default; + //ArrayBase & operator=(ArrayBase && other) = default; + + virtual ~ArrayBase() = default; + - virtual ~ArrayBase(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// get the amount of space allocated in bytes inline UInt getMemorySize() const; /// set the size to zero without freeing the allocated space inline void empty(); /// function to print the containt of the class virtual void printself(std::ostream & stream, int indent = 0) const; /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: /// Get the real size allocated in memory AKANTU_GET_MACRO(AllocatedSize, allocated_size, UInt); /// Get the Size of the Array UInt getSize() const __attribute__((deprecated)) { return size_; } UInt size() const { return size_; } /// Get the number of components AKANTU_GET_MACRO(NbComponent, nb_component, UInt); /// Get the name of th array AKANTU_GET_MACRO(ID, id, const ID &); /// Set the name of th array AKANTU_SET_MACRO(ID, id, const ID &); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: /// id of the vector ID id; /// the size allocated UInt allocated_size{0}; /// the size used UInt size_{0}; /// number of components UInt nb_component{1}; /// size of the stored type UInt size_of_type{0}; }; /* -------------------------------------------------------------------------- */ namespace { template struct IteratorHelper {}; template struct IteratorHelper<0, T> { using type = T; }; template struct IteratorHelper<1, T> { using type = Vector; }; template struct IteratorHelper<2, T> { using type = Matrix; }; template struct IteratorHelper<3, T> { using type = Tensor3; }; template using IteratorHelper_t = typename IteratorHelper::type; } // namespace /* -------------------------------------------------------------------------- */ template class Array : public ArrayBase { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: using value_type = T; using reference = value_type &; using pointer_type = value_type *; using const_reference = const value_type &; + inline ~Array() override; + /// Allocation of a new vector explicit inline Array(UInt size = 0, UInt nb_component = 1, const ID & id = ""); /// Allocation of a new vector with a default value Array(UInt size, UInt nb_component, const value_type def_values[], const ID & id = ""); /// Allocation of a new vector with a default value Array(UInt size, UInt nb_component, const_reference value, const ID & id = ""); /// Copy constructor (deep copy if deep=true) - Array(const Array & vect, bool deep = true, + Array(const Array & vect, //bool deep = true, const ID & id = ""); #ifndef SWIG /// Copy constructor (deep copy) explicit Array(const std::vector & vect); #endif - inline ~Array() override; + // copy operator + Array & operator=(const Array & other); + + // move constructor + Array(Array && other); - Array & operator=(const Array & a) { - /// this is to let STL allocate and copy arrays in the case of - /// std::vector::resize - AKANTU_DEBUG_ASSERT(this->size_ == 0, "Cannot copy akantu::Array"); - return const_cast(a); - } + // move assign + Array & operator=(Array && other); #ifndef SWIG /* ------------------------------------------------------------------------ */ /* Iterator */ /* ------------------------------------------------------------------------ */ /// \todo protected: does not compile with intel check why public: template ::value> class iterator_internal; public: /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ template class const_iterator; template class iterator; /* ------------------------------------------------------------------------ */ /// iterator for Array of nb_component = 1 using scalar_iterator = iterator; /// const_iterator for Array of nb_component = 1 using const_scalar_iterator = const_iterator; /// iterator returning Vectors of size n on entries of Array with /// nb_component = n using vector_iterator = iterator>; /// const_iterator returning Vectors of n size on entries of Array with /// nb_component = n using const_vector_iterator = const_iterator>; /// iterator returning Matrices of size (m, n) on entries of Array with /// nb_component = m*n using matrix_iterator = iterator>; /// const iterator returning Matrices of size (m, n) on entries of Array with /// nb_component = m*n using const_matrix_iterator = const_iterator>; /// iterator returning Tensor3 of size (m, n, k) on entries of Array with /// nb_component = m*n*k using tensor3_iterator = iterator>; /// const iterator returning Tensor3 of size (m, n, k) on entries of Array /// with nb_component = m*n*k using const_tensor3_iterator = const_iterator>; /* ------------------------------------------------------------------------ */ template inline decltype(auto) begin(Ns &&... n); template inline decltype(auto) end(Ns &&... n); template inline decltype(auto) begin(Ns &&... n) const; template inline decltype(auto) end(Ns &&... n) const; template inline decltype(auto) begin_reinterpret(Ns &&... n); template inline decltype(auto) end_reinterpret(Ns &&... n); template inline decltype(auto) begin_reinterpret(Ns &&... n) const; template inline decltype(auto) end_reinterpret(Ns &&... n) const; #endif // SWIG /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// append a tuple of size nb_component containing value inline void push_back(const_reference value); /// append a vector // inline void push_back(const value_type new_elem[]); #ifndef SWIG /// append a Vector or a Matrix template