diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 48fde570c..b6a1e7ac7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,53 +1,53 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux # @author Nicolas Richart # # @date creation: Fri Feb 24 2012 # @date last modification: Tue Sep 23 2014 # # @brief List of examples # # @section LICENSE # # Copyright (©) 2010-2012, 2014 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 # #=============================================================================== include_directories( ${AKANTU_INCLUDE_DIRS} ${AKANTU_EXTERNAL_LIB_INCLUDE_DIR} ) #=============================================================================== add_example(new_material "Example on how to add a new material in Akantu" PACKAGE core) add_example(boundary_conditions "Example on hoy to set boundary conditions" PACKAGE core) add_example(explicit "Example on how to run an explicit simulation" PACKAGE core) add_example(io "Example on how to perform Input/Output operations" PACKAGE core) add_example(implicit "Example on how to run an implicit simulation" PACKAGE implicit) add_example(static "Example on how to run a static simulation" PACKAGE implicit) add_example(parallel_2d "Example of how to write a parallel code with Akantu" PACKAGE parallel) add_example(cohesive_element "Cohesive element examples" PACKAGE cohesive_element) add_example(contact "Examples on how to use contact within Akantu" PACKAGE contact) add_example(optimization "Optimization examples" PACKAGE optimization) add_example(structural_mechanics "Structural mechanics model examples" PACKAGE structural_mechanics) add_example(heat_transfer "Example on how to run heat transfer simulation" PACKAGE heat_transfer) -add_example(embedded "Example on how to run embedded model simulation" PACKAGE embedded implicit) +add_example(embedded "Example on how to run embedded model simulation" PACKAGE embedded) #=============================================================================== diff --git a/examples/io/CMakeLists.txt b/examples/io/CMakeLists.txt index 9ab6d1d8b..fdbbc040b 100644 --- a/examples/io/CMakeLists.txt +++ b/examples/io/CMakeLists.txt @@ -1,29 +1,30 @@ #=============================================================================== # @file CMakeLists.txt # # @author Fabian Barras # # @date creation: Fri Aug 14 2015 # # @brief CMakeLists for Input/Output examples # # @section LICENSE # # Copyright (©) 2014 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 . # #=============================================================================== add_example(dumper "Examples on how to use DumperIOHelper to output data" PACKAGE iohelper) +add_example(parser "Examples on how to input data from text file in Akantu" PACKAGE core) diff --git a/examples/io/CMakeLists.txt b/examples/io/parser/CMakeLists.txt similarity index 72% copy from examples/io/CMakeLists.txt copy to examples/io/parser/CMakeLists.txt index 9ab6d1d8b..b304736f0 100644 --- a/examples/io/CMakeLists.txt +++ b/examples/io/parser/CMakeLists.txt @@ -1,29 +1,44 @@ #=============================================================================== # @file CMakeLists.txt # # @author Fabian Barras # -# @date creation: Fri Aug 14 2015 -# -# @brief CMakeLists for Input/Output examples +# @date creation: Mon Dec 14 09:07:44 2015 +# +# @brief Tests insertion of cohesive elements # # @section LICENSE # # Copyright (©) 2014 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 +# #=============================================================================== -add_example(dumper "Examples on how to use DumperIOHelper to output data" PACKAGE iohelper) +add_mesh(swiss_cheese swiss_cheese.geo 2 2) + +register_example(example_parser + example_parser.cc + USE IOHelper + DEPENDS swiss_cheese + DIRECTORIES_TO_CREATE paraview + ) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/input_file.dat + ${CMAKE_CURRENT_BINARY_DIR}/input_file.dat + COPYONLY + ) diff --git a/examples/io/parser/example_parser.cc b/examples/io/parser/example_parser.cc new file mode 100644 index 000000000..b431faf80 --- /dev/null +++ b/examples/io/parser/example_parser.cc @@ -0,0 +1,80 @@ +/** + * @file example_parser.cc + * @author Fabian Barras + * @date Mon Dec 14 09:45:20 2015 + * + * @brief Example on how to parse input text file + * + * @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" +#include "mesh.hh" +#include "solid_mechanics_model.hh" +/* -------------------------------------------------------------------------- */ +using namespace akantu; + +int main(int argc, char *argv[]) { + + // Precise in initialize the name of the text input file to parse. + initialize("input_file.dat", argc, argv); + + // Get the user ParserSection. + const ParserSection & usersect = getUserParser(); + + // getParameterValue() allows to extract data associated to a given parameter name + // and cast it in the desired type set as template paramter. + Mesh mesh(usersect.getParameterValue("spatial_dimension")); + mesh.read(usersect.getParameterValue("mesh_file")); + + // getParameter() can be used with variable declaration (destination type is explicitly known). + UInt max_iter = usersect.getParameter("max_nb_iterations"); + Real precision = usersect.getParameter("precision"); + + // Following NumPy convention, data can be interpreted as Vector or Matrix structures. + Matrix eigen_stress = usersect.getParameter("stress"); + + SolidMechanicsModel model(mesh); + mesh.createGroupsFromMeshData("physical_names"); + model.initFull(SolidMechanicsModelOptions(_static)); + + model.applyBC(BC::Dirichlet::FixedValue(0.0, _x), usersect.getParameterValue("outter_crust")); + model.applyBC(BC::Dirichlet::FixedValue(0.0, _y), usersect.getParameterValue("outter_crust")); + model.applyBC(BC::Neumann::FromStress(eigen_stress), usersect.getParameterValue("inner_holes")); + + model.setDirectory("./paraview"); + model.setBaseName("swiss_cheese"); + model.addDumpFieldVector("displacement"); + + model.solveStep<_scm_newton_raphson_tangent, _scc_increment>(precision, max_iter); + + model.dump(); + + finalize(); + + return EXIT_SUCCESS; +} diff --git a/examples/io/parser/input_file.dat b/examples/io/parser/input_file.dat new file mode 100644 index 000000000..15c8fd6fc --- /dev/null +++ b/examples/io/parser/input_file.dat @@ -0,0 +1,17 @@ +material elastic [ + name = cheese + rho = 1100 + nu = 0.45 + E = 1e5 +] + +user parameters [ + spatial_dimension = 2 + mesh_file = swiss_cheese.msh + inner_holes = holes + outter_crust = crust + lactostatic_p = 30e3 + stress = [[lactostatic_p,0],[0,lactostatic_p]] + max_nb_iterations = 100 + precision = 1e-9 +] diff --git a/examples/io/parser/swiss_cheese.geo b/examples/io/parser/swiss_cheese.geo new file mode 100644 index 000000000..a6ca2dcd3 --- /dev/null +++ b/examples/io/parser/swiss_cheese.geo @@ -0,0 +1,76 @@ +dx = 0.01; +w = 0.2; +radius = 0.015; + +Point(1) = {0,0,0,dx}; +Point(2) = {0,.03,0,dx}; +Point(3) = {0,-.03,0,dx}; +Point(4) = {w,0,0,dx}; +Point(5) = {w,.03,0,dx}; +Point(6) = {w,-.03,0,dx}; +Point(7) = {0,w,0,dx}; +Point(8) = {0,w,0.3,dx}; +Point(9) = {0,w,-.03,dx}; +Point(10) = {w,w,0,dx}; +Point(11) = {w,w,.03,dx}; +Point(12) = {w,w,-.03,dx}; +Point(13) = {0.5*w,0.5*w,0,dx}; +Point(14) = {0.5*w+radius,0.5*w+radius,0,dx}; +Point(15) = {0.5*w-radius,0.5*w+radius,0,dx}; +Point(16) = {0.5*w+radius,0.5*w-radius,0,dx}; +Point(17) = {0.5*w-radius,0.5*w-radius,0,dx}; +Line(1) = {1, 2}; +Line(2) = {2, 5}; +Line(3) = {5, 4}; +Line(4) = {1, 4}; +Line(5) = {1, 3}; +Line(6) = {6, 4}; +Line(7) = {3, 6}; +Line(8) = {8, 11}; +Line(9) = {7, 10}; +Line(10) = {9, 12}; +Line(11) = {8, 7}; +Line(12) = {11, 10}; +Line(13) = {10, 12}; +Line(14) = {7, 9}; +Line(15) = {2, 8}; +Line(16) = {1, 7}; +Line(17) = {3, 9}; +Line(18) = {5, 11}; +Line(19) = {4, 10}; +Line(20) = {6, 12}; +Circle(41) = {16, 13, 14}; +Circle(42) = {14, 13, 15}; +Circle(43) = {15, 13, 17}; +Circle(44) = {17, 13, 16}; +Translate {0.05, 0.05, 0} { + Duplicata { Line{44, 43, 42, 41}; } +} +Translate {-0.05, 0.05, 0} { + Duplicata { Line{44, 43, 42, 41}; } +} +Translate {0.05, -0.05,0} { + Duplicata { Line{44, 43, 42, 41}; } +} +Translate {-0.05,-0.05,0} { + Duplicata { Line{44, 43, 42, 41}; } +} +Delete { + Line{2, 15, 1, 3, 18, 8, 7, 5, 17, 14, 10, 13, 12, 20}; +} +Delete { + Line{11, 6}; +} +Delete { + Point{2, 3, 9, 12, 11, 5, 8, 6}; +} +Line Loop(61) = {4, 19, -9, -16}; +Line Loop(62) = {60, 59, 58, 57}; +Line Loop(63) = {44, 41, 42, 43}; +Line Loop(64) = {55, 54, 53, 56}; +Line Loop(65) = {52, 51, 50, 49}; +Line Loop(66) = {46, 45, 48, 47}; +Plane Surface(67) = {61, 62, 63, 64, 65, 66}; +Physical Surface("cheese") = {67}; +Physical Line("holes") = {60, 57, 58, 59, 56, 53, 54, 55, 41, 44, 43, 42, 52, 51, 50, 49, 45, 48, 47, 46}; +Physical Line("crust") = {4, 19, 9, 16};