diff --git a/test/test_mesh_utils/test_segment_nodetype/test_segment_nodetype.cc b/test/test_mesh_utils/test_segment_nodetype/test_segment_nodetype.cc index fc9fadad7..ef565d8c3 100644 --- a/test/test_mesh_utils/test_segment_nodetype/test_segment_nodetype.cc +++ b/test/test_mesh_utils/test_segment_nodetype/test_segment_nodetype.cc @@ -1,107 +1,104 @@ /** * @file test_segment_nodetype.cc * * @author Marco Vocialta * * @date creation: Fri Sep 18 2015 * * @brief Test to verify that the node type is correctly associated to * the segments in parallel * * @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 "mesh_utils.hh" #include "distributed_synchronizer.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char * argv[]) { initialize(argc, argv); UInt spatial_dimension = 3; Mesh mesh(spatial_dimension); StaticCommunicator & comm = StaticCommunicator::getStaticCommunicator(); Int psize = comm.getNbProc(); Int prank = comm.whoAmI(); DistributedSynchronizer * dist = NULL; // partition the mesh if (prank == 0) { mesh.read("mesh.msh"); MeshPartitionScotch partition(mesh, spatial_dimension); partition.partitionate(psize); dist = DistributedSynchronizer::createDistributedSynchronizerMesh( mesh, &partition); } else { dist = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, NULL); } // compute the node types for each segment Mesh mesh_facets(mesh.initMeshFacets()); MeshUtils::buildSegmentToNodeType(mesh, mesh_facets, dist); // verify that the number of segments per node type makes sense std::map nb_facets_per_nodetype; UInt nb_segments = 0; - for (ghost_type_t::iterator gt = ghost_type_t::begin(); - gt != ghost_type_t::end(); ++gt) { - GhostType ghost_type = *gt; - + for (auto ghost_type : ghost_types) { const Array & segment_to_nodetype = mesh_facets.getData("segment_to_nodetype", _segment_2, ghost_type); // count the number of segments per node type for (UInt s = 0; s < segment_to_nodetype.getSize(); ++s) { if (nb_facets_per_nodetype.find(segment_to_nodetype(s)) == nb_facets_per_nodetype.end()) nb_facets_per_nodetype[segment_to_nodetype(s)] = 1; else ++nb_facets_per_nodetype[segment_to_nodetype(s)]; } nb_segments += segment_to_nodetype.getSize(); } // checking the solution if (nb_segments != 24) AKANTU_DEBUG_ERROR("The number of segments is wrong"); if (prank == 0) { if (nb_facets_per_nodetype[-1] != 3 || nb_facets_per_nodetype[-2] != 9 || nb_facets_per_nodetype[-3] != 12) AKANTU_DEBUG_ERROR( "The segments of processor 0 have the wrong node type"); if (nb_facets_per_nodetype.size() > 3) AKANTU_DEBUG_ERROR("Processor 0 cannot have any slave segment"); } if (prank == psize - 1 && nb_facets_per_nodetype.find(-2) != nb_facets_per_nodetype.end()) AKANTU_DEBUG_ERROR("The last processor must not have any master facets"); finalize(); return 0; } diff --git a/test/test_synchronizer/test_grid_synchronizer.cc b/test/test_synchronizer/test_grid_synchronizer.cc index babdcd7a1..cfea77437 100644 --- a/test/test_synchronizer/test_grid_synchronizer.cc +++ b/test/test_synchronizer/test_grid_synchronizer.cc @@ -1,298 +1,299 @@ /** * @file test_grid_synchronizer.cc * * @author Nicolas Richart * * @date creation: Wed Sep 01 2010 * @date last modification: Fri Feb 27 2015 * * @brief test the GridSynchronizer object * * @section LICENSE * * Copyright (©) 2010-2012, 2014, 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 "aka_common.hh" #include "aka_grid_dynamic.hh" #include "mesh.hh" #include "grid_synchronizer.hh" #include "mesh_partition.hh" #include "synchronizer_registry.hh" #include "test_data_accessor.hh" #ifdef AKANTU_USE_IOHELPER # include "io_helper.hh" #endif //AKANTU_USE_IOHELPER using namespace akantu; -const UInt spatial_dimension = 3; +const UInt spatial_dimension = 2; typedef std::map, Real> pair_list; #include "test_grid_tools.hh" static void updatePairList(const ElementTypeMapArray & barycenter, const SpatialGrid & grid, Real radius, pair_list & neighbors, neighbors_map_t::type & neighbors_map) { AKANTU_DEBUG_IN(); GhostType ghost_type = _not_ghost; Element e; e.ghost_type = ghost_type; // generate the pair of neighbor depending of the cell_list ElementTypeMapArray::type_iterator it = barycenter.firstType(_all_dimensions, ghost_type); ElementTypeMapArray::type_iterator last_type = barycenter.lastType(0, ghost_type); for(; it != last_type; ++it) { // loop over quad points e.type = *it; e.element = 0; const Array & barycenter_vect = barycenter(*it, ghost_type); UInt sp = barycenter_vect.getNbComponent(); Array::const_iterator< Vector > bary = barycenter_vect.begin(sp); Array::const_iterator< Vector > bary_end = barycenter_vect.end(sp); for(;bary != bary_end; ++bary, e.element++) { #if !defined(AKANTU_NDEBUG) Point pt1(*bary); #endif SpatialGrid::CellID cell_id = grid.getCellID(*bary); SpatialGrid::neighbor_cells_iterator first_neigh_cell = grid.beginNeighborCells(cell_id); SpatialGrid::neighbor_cells_iterator last_neigh_cell = grid.endNeighborCells(cell_id); // loop over neighbors cells of the one containing the current element for (; first_neigh_cell != last_neigh_cell; ++first_neigh_cell) { SpatialGrid::Cell::const_iterator first_neigh_el = grid.beginCell(*first_neigh_cell); SpatialGrid::Cell::const_iterator last_neigh_el = grid.endCell(*first_neigh_cell); // loop over the quadrature point in the current cell of the cell list for (;first_neigh_el != last_neigh_el; ++first_neigh_el){ const Element & elem = *first_neigh_el; Array::const_iterator< Vector > neigh_it = barycenter(elem.type, elem.ghost_type).begin(sp); const Vector & neigh_bary = neigh_it[elem.element]; Real distance = bary->distance(neigh_bary); if(distance <= radius) { #if !defined(AKANTU_NDEBUG) Point pt2(neigh_bary); neighbors_map[pt1].push_back(pt2); #endif std::pair pair = std::make_pair(e, elem); pair_list::iterator p = neighbors.find(pair); if(p != neighbors.end()) { AKANTU_DEBUG_ERROR("Pair already registered [" << e << " " << elem << "] -> " << p->second << " " << distance); } else { neighbors[pair] = distance; } } } } } } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ /* Main */ /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { akantu::initialize(argc, argv); Real radius = 0.001; Mesh mesh(spatial_dimension); StaticCommunicator & comm = StaticCommunicator::getStaticCommunicator(); Int psize = comm.getNbProc(); Int prank = comm.whoAmI(); DistributedSynchronizer * dist = NULL; if(prank == 0) { mesh.read("bar.msh"); MeshPartition * partition = new MeshPartitionScotch(mesh, spatial_dimension); partition->partitionate(psize); dist = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, partition); delete partition; } else { dist = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, NULL); } mesh.computeBoundingBox(); const Vector & lower_bounds = mesh.getLowerBounds(); const Vector & upper_bounds = mesh.getUpperBounds(); Vector center = 0.5 * (upper_bounds + lower_bounds); Vector spacing(spatial_dimension); for (UInt i = 0; i < spatial_dimension; ++i) { spacing[i] = radius * 1.2; } SpatialGrid grid(spatial_dimension, spacing, center); GhostType ghost_type = _not_ghost; Mesh::type_iterator it = mesh.firstType(spatial_dimension, ghost_type); Mesh::type_iterator last_type = mesh.lastType(spatial_dimension, ghost_type); ElementTypeMapArray barycenters("", ""); mesh.initElementTypeMapArray(barycenters, spatial_dimension, spatial_dimension); Element e; e.ghost_type = ghost_type; for(; it != last_type; ++it) { UInt nb_element = mesh.getNbElement(*it, ghost_type); e.type = *it; Array & barycenter = barycenters(*it, ghost_type); barycenter.resize(nb_element); Array::iterator< Vector > bary_it = barycenter.begin(spatial_dimension); for (UInt elem = 0; elem < nb_element; ++elem) { mesh.getBarycenter(elem, *it, bary_it->storage(), ghost_type); e.element = elem; grid.insert(e, *bary_it); ++bary_it; } } std::stringstream sstr; sstr << "mesh_" << prank << ".msh"; mesh.write(sstr.str()); Mesh grid_mesh(spatial_dimension, "grid_mesh", 0); std::stringstream sstr_grid; sstr_grid << "grid_mesh_" << prank << ".msh"; grid.saveAsMesh(grid_mesh); grid_mesh.write(sstr_grid.str()); std::cout << "Pouet 1" << std::endl; AKANTU_DEBUG_INFO("Creating TestAccessor"); TestAccessor test_accessor(mesh, barycenters); SynchronizerRegistry synch_registry(test_accessor); GridSynchronizer * grid_communicator = GridSynchronizer::createGridSynchronizer(mesh, grid); std::cout << "Pouet 2" << std::endl; ghost_type = _ghost; it = mesh.firstType(spatial_dimension, ghost_type); last_type = mesh.lastType(spatial_dimension, ghost_type); e.ghost_type = ghost_type; for(; it != last_type; ++it) { UInt nb_element = mesh.getNbElement(*it, ghost_type); e.type = *it; Array & barycenter = barycenters(*it, ghost_type); barycenter.resize(nb_element); Array::iterator< Vector > bary_it = barycenter.begin(spatial_dimension); for (UInt elem = 0; elem < nb_element; ++elem) { mesh.getBarycenter(elem, *it, bary_it->storage(), ghost_type); e.element = elem; grid.insert(e, *bary_it); ++bary_it; } } Mesh grid_mesh_ghost(spatial_dimension, "grid_mesh_ghost", 0); std::stringstream sstr_gridg; sstr_gridg << "grid_mesh_ghost_" << prank << ".msh"; grid.saveAsMesh(grid_mesh_ghost); grid_mesh_ghost.write(sstr_gridg.str()); std::cout << "Pouet 3" << std::endl; neighbors_map_t::type neighbors_map; pair_list neighbors; updatePairList(barycenters, grid, radius, neighbors, neighbors_map); pair_list::iterator nit = neighbors.begin(); pair_list::iterator nend = neighbors.end(); std::stringstream sstrp; sstrp << "pairs_" << prank; std::ofstream fout(sstrp.str().c_str()); for(;nit != nend; ++nit) { fout << "[" << nit->first.first << "," << nit->first.second << "] -> " << nit->second << std::endl; } std::string file = "neighbors_ref"; - std::stringstream sstrf; sstrf << file << "_" << prank; + std::stringstream sstrf; sstrf << file << "_" << psize << "_" << prank; + file = sstrf.str(); std::ofstream nout; nout.open(file.c_str()); neighbors_map_t::type::iterator it_n = neighbors_map.begin(); neighbors_map_t::type::iterator end_n = neighbors_map.end(); for(;it_n != end_n; ++it_n) { std::sort(it_n->second.begin(), it_n->second.end()); std::vector< Point >::iterator it_v = it_n->second.begin(); std::vector< Point >::iterator end_v = it_n->second.end(); nout << "####" << std::endl; nout << it_n->second.size() << std::endl; nout << it_n->first << std::endl; nout << "#" << std::endl; for(;it_v != end_v; ++it_v) { nout << *it_v << std::endl; } } fout.close(); synch_registry.registerSynchronizer(*dist, _gst_smm_mass); synch_registry.registerSynchronizer(*grid_communicator, _gst_test); AKANTU_DEBUG_INFO("Synchronizing tag on Dist"); synch_registry.synchronize(_gst_smm_mass); AKANTU_DEBUG_INFO("Synchronizing tag on Grid"); synch_registry.synchronize(_gst_test); delete grid_communicator; delete dist; akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_synchronizer/test_grid_synchronizer_check_neighbors.cc b/test/test_synchronizer/test_grid_synchronizer_check_neighbors.cc index d7ca9bb56..a9ee15a17 100644 --- a/test/test_synchronizer/test_grid_synchronizer_check_neighbors.cc +++ b/test/test_synchronizer/test_grid_synchronizer_check_neighbors.cc @@ -1,122 +1,122 @@ /** * @file test_grid_synchronizer_check_neighbors.cc * * @author Nicolas Richart * * @date creation: Mon Mar 11 2013 * @date last modification: Fri Feb 27 2015 * * @brief Test the generation of neighbors list based on a akaentu::Grid * * @section LICENSE * * Copyright (©) 2014, 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 #include #include #include "aka_common.hh" #include "static_communicator.hh" using namespace akantu; const UInt spatial_dimension = 3; #include "test_grid_tools.hh" void readNeighbors(std::ifstream & nin, neighbors_map_t::type & neighbors_map_read) { std::string line; while (std::getline(nin, line)) { std::getline(nin, line); std::istringstream iss(line); UInt nb_neig; iss >> nb_neig; std::getline(nin, line); Point pt; pt.read(line); std::getline(nin, line); for (UInt i = 0; i < nb_neig; ++i) { std::getline(nin, line); Point ne; ne.read(line); neighbors_map_read[pt].push_back(ne); } } } int main(int argc, char *argv[]) { initialize(argc, argv); StaticCommunicator & comm = StaticCommunicator::getStaticCommunicator(); - // Int psize = comm.getNbProc(); + Int psize = comm.getNbProc(); Int prank = comm.whoAmI(); - std::string file_ref = "neighbors_ref"; - std::string file = file_ref; - std::stringstream sstr; sstr << file << "_" << prank; + std::string file_ref = "neighbors_ref_1_0"; + std::string file = "neighbors_ref"; + std::stringstream sstr; sstr << file << "_" << psize << "_" << prank; file = sstr.str(); std::ifstream nin; neighbors_map_t::type neighbors_map_read; nin.open(file_ref.c_str()); readNeighbors(nin, neighbors_map_read); nin.close(); neighbors_map_t::type neighbors_map; nin.open(file.c_str()); readNeighbors(nin, neighbors_map); nin.close(); neighbors_map_t::type::iterator it_n = neighbors_map.begin(); neighbors_map_t::type::iterator end_n = neighbors_map.end(); for(;it_n != end_n; ++it_n) { std::sort(it_n->second.begin(), it_n->second.end()); std::vector< Point >::iterator it_v = it_n->second.begin(); std::vector< Point >::iterator end_v = it_n->second.end(); neighbors_map_t::type::iterator it_nr = neighbors_map_read.find(it_n->first); if(it_nr == neighbors_map_read.end()) AKANTU_DEBUG_ERROR("Argh what is this point that is not present in the ref file " << it_n->first); std::vector< Point >::iterator it_vr = it_nr->second.begin(); std::vector< Point >::iterator end_vr = it_nr->second.end(); for(;it_v != end_v && it_vr != end_vr; ++it_v, ++it_vr) { if(*it_vr != *it_v) AKANTU_DEBUG_ERROR("Neighbors does not match " << *it_v << " != " << *it_vr << " neighbor of " << it_n->first); } if(it_v == end_v && it_vr != end_vr) { AKANTU_DEBUG_ERROR("Some neighbors of " << it_n->first << " are missing!"); } if(it_v != end_v && it_vr == end_vr) AKANTU_DEBUG_ERROR("Some neighbors of " << it_n->first << " are in excess!"); } akantu::finalize(); return EXIT_SUCCESS; }