diff --git a/test/test_fem/CMakeLists.txt b/test/test_fem/CMakeLists.txt index 39a5fdd7c..4b0a83eaa 100644 --- a/test/test_fem/CMakeLists.txt +++ b/test/test_fem/CMakeLists.txt @@ -1,77 +1,78 @@ #=============================================================================== # @file CMakeLists.txt # @author Guillaume Anciaux # @date Fri Jun 11 09:46:59 2010 # # @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 . # # @section DESCRIPTION # #=============================================================================== #=============================================================================== register_test(test_interpolate_bernoulli_beam_2 test_interpolate_bernoulli_beam_2.cc) #=============================================================================== set(LIST_TYPES segment_2 segment_3 triangle_3 triangle_6 quadrangle_4 quadrangle_8 tetrahedron_4 tetrahedron_10 hexahedron_8 ) add_mesh(test_fem_segment_2_mesh line.geo 1 1 OUTPUT segment_2.msh) add_mesh(test_fem_segment_3_mesh line.geo 1 2 OUTPUT segment_3.msh) add_mesh(test_fem_triangle_3_mesh square.geo 2 1 OUTPUT triangle_3.msh) add_mesh(test_fem_triangle_6_mesh square.geo 2 2 OUTPUT triangle_6.msh) add_mesh(test_fem_quadrangle_4_mesh square_structured.geo 2 1 OUTPUT quadrangle_4.msh) add_mesh(test_fem_quadrangle_8_mesh square_structured.geo 2 2 OUTPUT quadrangle_8.msh) add_mesh(test_fem_tetrahedron_4_mesh cube.geo 3 1 OUTPUT tetrahedron_4.msh) add_mesh(test_fem_tetrahedron_10_mesh cube.geo 3 2 OUTPUT tetrahedron_10.msh) add_mesh(test_fem_hexahedron_8_mesh hexa_structured.geo 3 1 OUTPUT hexahedron_8.msh) macro(register_fem_test operation type) set(_target test_${operation}_${_type}) register_test(${_target} test_${operation}.cc) set_target_properties(${_target} PROPERTIES COMPILE_DEFINITIONS TYPE=_${_type}) if(NOT EXISTS ${_type}.msh) add_dependencies(${_target} test_fem_${_type}_mesh) endif() endmacro() foreach(_type ${LIST_TYPES}) register_fem_test(interpolate ${_type}) register_fem_test(gradient ${_type}) register_fem_test(integrate ${_type}) + register_fem_test(inverse_map ${_type}) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_type}.msh) file(COPY ${_type}.msh DESTINATION .) endif() endforeach() #add_mesh(test_fem_circle_1_mesh circle.geo 2 1 OUTPUT circle1.msh) #add_mesh(test_fem_circle_2_mesh circle.geo 2 2 OUTPUT circle2.msh) diff --git a/test/test_fem/test_inverse_map.cc b/test/test_fem/test_inverse_map.cc new file mode 100644 index 000000000..c54650681 --- /dev/null +++ b/test/test_fem/test_inverse_map.cc @@ -0,0 +1,103 @@ +/** + * @file test_inverse_map_XXXX.cc + * @author Guillaume Anciaux + * @date Mon Jul 19 10:55:49 2010 + * + * @brief test of the fem class + * + * @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 "aka_common.hh" +#include "fem.hh" +#include "mesh.hh" +#include "mesh_io.hh" +#include "mesh_io_msh.hh" +#include "shape_lagrange.hh" +#include "integrator_gauss.hh" +/* -------------------------------------------------------------------------- */ +#include +#include +#include +/* -------------------------------------------------------------------------- */ +using namespace akantu; + +int main(int argc, char *argv[]) { + akantu::initialize(argc, argv); + + debug::setDebugLevel(dblTest); + const ElementType type = TYPE; + UInt dim = ElementClass::getSpatialDimension(); + + MeshIOMSH mesh_io; + Mesh my_mesh(dim); + + std::stringstream meshfilename; meshfilename << type << ".msh"; + mesh_io.read(meshfilename.str(), my_mesh); + + UInt nb_elements = my_mesh.getNbElement(type); + /// + FEMTemplate *fem = + new FEMTemplate(my_mesh, dim, "my_fem"); + + fem->initShapeFunctions(); + + UInt nb_quad_points = fem->getNbQuadraturePoints(type); + + /// get the quadrature points coordinates + Vector coord_on_quad(nb_quad_points*nb_elements, + my_mesh.getSpatialDimension(), + "coord_on_quad"); + + fem->interpolateOnQuadraturePoints(my_mesh.getNodes(), + coord_on_quad, + my_mesh.getSpatialDimension(), + type); + + + /// loop over the quadrature points + Vector::iterator it = coord_on_quad.begin(dim); + types::RVector natural_coords(dim); + + Real * quad = ElementClass::getQuadraturePoints(); + + for(UInt el = 0 ; el < nb_elements ; ++el){ + for(UInt q = 0 ; q < nb_quad_points ; ++q){ + fem->inverseMap(*it,el,type,natural_coords); + for (UInt i = 0; i < dim; ++i) { + const Real eps = 1e-15; + AKANTU_DEBUG_ASSERT(fabs(natural_coords[i] - quad[i]) < eps, + "real coordinates inversion test failed:" + << natural_coords[i] << " - " << quad[i] + << " = " << natural_coords[i] - quad[i]); + } + ++it; + } + } + + std::cout << "inverse completed over " << nb_elements << " elements" << std::endl; + + + delete fem; + finalize(); + + return EXIT_SUCCESS; +}