diff --git a/CMakeLists.txt b/CMakeLists.txt index 50128d6..97579a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,10 @@ -project(toto) +project(perf-bench) cmake_minimum_required(VERSION 2.8.12) find_package(Akantu) add_akantu_simulation(perf_test SOURCES perf-test.cc FILES_TO_COPY material.dat bar.msh) -add_akantu_simulation(test_mm - SOURCES test.cc - FILES_TO_COPY test.dat test.msh) +set_target_properties(perf_test PROPERTIES CXX_STANDARD 14) diff --git a/material.dat b/material.dat index 705741e..31cf60c 100644 --- a/material.dat +++ b/material.dat @@ -1,21 +1,6 @@ material elastic [ name = steel rho = 7800 # density E = 2.1e11 # young's modulus nu = 0.3 # poisson's ratio ] - -model_solver solid_mechanics_model [ - time_step_solver implicit [ - type = dynamic - non_linear_solver implicit [ - type = newton_raphson_modified - max_iterations = 15 - tolerance = 1e-7 - ] - - integration_scheme displacement [ - type = trapezoidal_rule_2 - ] - ] -] diff --git a/perf-test.cc b/perf-test.cc index d3b74f4..de7101b 100644 --- a/perf-test.cc +++ b/perf-test.cc @@ -1,235 +1,253 @@ /** * @file scalability_test.cc * @author Nicolas Richart * @date Tue Feb 22 09:35:58 2011 * * @brief Test de scalability * * @section LICENSE * * Copyright (©) 2010-2011 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 /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #if (((AKANTU_VERSION_MAJOR >= 2) && (AKANTU_VERSION_MINOR >= 1)) || \ (AKANTU_VERSION_MAJOR >= 3)) #include "aka_array.hh" #else #include "aka_vector.hh" #endif //#define DUMPS_energy -#define DUMPS_paraview +//#define DUMPS_paraview #include "mesh.hh" #include "mesh_io.hh" #include "solid_mechanics_model.hh" +#include "static_communicator.hh" using namespace akantu; + typedef std::chrono::high_resolution_clock clk; using std::chrono::duration_cast; using std::chrono::microseconds; //#define AKANTU_VERSION_MAJOR 2 - class Chrono { public: inline void start() { _start = clk::now(); }; inline void store_time(const std::string & type) { clk::time_point _end = clk::now(); if (measures.find(type) == measures.end()) { measures[type] = duration_cast(_end - _start); nb_measures[type] = 1; } else { measures[type] += duration_cast(_end - _start); ++nb_measures[type]; } _start = clk::now(); } virtual void printself(std::ostream & stream, int indent = 0) const { std::string space; for (Int i = 0; i < indent; i++, space += AKANTU_INDENT) ; stream << space << "Chrono [" << std::endl; std::map::const_iterator it; for (it = measures.begin(); it != measures.end(); ++it) { const std::pair & p = *it; const unsigned int & nb_measure = nb_measures.find(p.first)->second; stream << space << " + " << p.first << "\t: " << std::setw(7) << std::fixed << std::setprecision(0) << p.second.count() / double(nb_measure) << "us" << std::endl; } stream << space << "]" << std::endl; } private: clk::time_point _start; std::map measures; std::map nb_measures; }; inline std::ostream & operator<<(std::ostream & stream, const Chrono & _this) { _this.printself(stream); return stream; } int main(int argc, char * argv[]) { - akantu::debug::setDebugLevel(akantu::dblWarning); + debug::setDebugLevel(dblWarning); initialize("material.dat", argc, argv); StaticCommunicator & comm = - akantu::StaticCommunicator::getStaticCommunicator(); + StaticCommunicator::getStaticCommunicator(); Int psize = comm.getNbProc(); Int prank = comm.whoAmI(); /* -------------------------------------------------------------------------- */ UInt spatial_dimension = 2; UInt max_steps = 1000; Real time_factor = 0.8; const Real pulse_width = .5; const Real A = 0.01; Real width = 1; Real height = 0.2; Chrono chrono; chrono.start(); /* ------------------------------------------------------------------------ */ Mesh mesh(spatial_dimension); - // akantu::MeshPartition * partition = NULL; - // if(prank == 0) { - MeshIOMSH mesh_io; - mesh_io.read("bar.msh", mesh); - // partition = new MeshPartitionScotch(mesh, spatial_dimension); - // partition->partitionate(psize); - // } +#if AKANTU_VERSION_MAJOR < 3 + MeshPartition * partition = NULL; +#endif + + if(prank == 0) { +#if (AKANTU_VERSION_MAJOR < 3) && (AKANTU_VERSION_MINOR <= 2) + MeshIOMSH mesh_io; + mesh_io.read("bar.msh", mesh); +#else + mesh.read("bar.msh"); +#endif + +#if AKANTU_VERSION_MAJOR < 3 + partition = new MeshPartitionScotch(mesh, spatial_dimension); + partition->partitionate(psize); +#endif + } + +#if AKANTU_VERSION_MAJOR >= 3 + mesh.distribute(); +#endif /// model initialization SolidMechanicsModel model(mesh); - // model.initParallel(partition); - model.initFull(SolidMechanicsModelOptions(_implicit_dynamic)); +#if AKANTU_VERSION_MAJOR < 3 + model.initParallel(partition); +#endif + model.initFull(); #if AKANTU_VERSION_MAJOR < 3 model.assembleMassLumped(); -#else - model.assembleStiffnessMatrix(); #endif /// boundary conditions Real eps = 1e-16; #if AKANTU_VERSION_MAJOR < 2 const Vector & pos = mesh.getNodes(); Vector & boundary = model.getBoundary(); Vector & disp = model.getDisplacement(); #else const Array & pos = mesh.getNodes(); Array & boundary = model.getBlockedDOFs(); Array & disp = model.getDisplacement(); #endif UInt nb_nodes = mesh.getNbNodes(); for (UInt n = 0; n < nb_nodes; ++n) { Real x = pos(n, 0); // Sinus * Gaussian Real L = pulse_width; Real k = 0.1 * 2 * M_PI * 3 / L; disp(n, 0) = A * sin(k * x) * exp(-(k * x) * (k * x) / (L * L)); if (std::abs(pos(n, 0) + width / 2.) <= eps) boundary(n, 0) = true; // if((std::abs(pos(i, 1) - height/2.) <= eps) || (std::abs(pos(i, 1) + // height/2.) <= eps)) boundary(i, 1) = true; } #if defined(DUMPS_paraview) model.addDumpField("displacement"); model.addDumpField("velocity"); model.addDumpField("acceleration"); model.addDumpField("internal_force"); model.addDumpField("residual"); model.addDumpField("blocked_dofs"); model.addDumpField("mass"); #endif #if defined(DUMPS_energy) std::ofstream out; out.open("energies.csv"); out << "kinetic,potential" << std::endl; #endif - akantu::Real time_step = model.getStableTimeStep() * time_factor; + Real time_step = model.getStableTimeStep() * time_factor; model.setTimeStep(time_step); std::cout << "Time step: " << time_step << std::endl; chrono.store_time("initial"); Real epot, ekin; - for (akantu::UInt s = 1; s <= max_steps; ++s) { + for (UInt s = 1; s <= max_steps; ++s) { chrono.start(); #if (AKANTU_VERSION_MAJOR >= 3) model.solveStep(); - NonLinearSolver & nls = model.getDOFManager().getNonLinearSolver("implicit"); - UInt n_iter = nls.get("nb_iterations"); - Real error = nls.get("error"); - std::cout << n_iter << " -> " << error << std::endl; + // NonLinearSolver & nls = model.getDOFManager().getNonLinearSolver("implicit"); + // UInt n_iter = nls.get("nb_iterations"); + // Real error = nls.get("error"); + // std::cout << n_iter << " -> " << error << std::endl; #else model.explicitPred(); model.updateResidual(); model.updateAcceleration(); model.explicitCorr(); #endif chrono.store_time("solve_step"); +#if defined(DUMPS_energy) #if (((AKANTU_VERSION_MAJOR >= 2) && (AKANTU_VERSION_MINOR >= 2)) || \ (AKANTU_VERSION_MAJOR >= 3)) epot = model.getEnergy("potential"); ekin = model.getEnergy("kinetic"); #else epot = model.getPotentialEnergy(); ekin = model.getKineticEnergy(); #endif chrono.store_time("energies"); - -#if defined(DUMPS) out << ekin << "," << epot << std::endl; +#endif + + +#if defined(DUMPS_paraview) model.dump(); #endif } if (prank == 0) std::cout << chrono; finalize(); return EXIT_SUCCESS; }