diff --git a/test/test_model/test_phase_field_model/CMakeLists.txt b/test/test_model/test_phase_field_model/CMakeLists.txt index fa02e318a..5c25d7ccb 100644 --- a/test/test_model/test_phase_field_model/CMakeLists.txt +++ b/test/test_model/test_phase_field_model/CMakeLists.txt @@ -1,27 +1,40 @@ #=============================================================================== # @file CMakeLists.txt # # @author Mohit Pundir # # @date creation: Thu Dec 20 2018 # @date last modification: Thu Dec 20 2018 # # @brief test for the phase field model # # @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 . # #=============================================================================== register_test(test_phasefield_selector SOURCES test_phasefield_selector.cc FILES_TO_COPY phasefield_selector.dat phasefield_selector.msh PACKAGE core ) + + +register_test(test_phase_solid_coupling + SOURCES test_phase_solid_coupling.cc + FILES_TO_COPY material_coupling.dat test_one_element.msh + PACKAGE core + ) + +register_test(test_multi_material + SOURCES test_multi_material.cc + FILES_TO_COPY material_multiple.dat test_two_element.msh + PACKAGE core + ) diff --git a/test/test_model/test_phase_field_model/material_coupling.dat b/test/test_model/test_phase_field_model/material_coupling.dat index 9eb1a0915..2867469f8 100644 --- a/test/test_model/test_phase_field_model/material_coupling.dat +++ b/test/test_model/test_phase_field_model/material_coupling.dat @@ -1,14 +1,15 @@ material phasefield [ name = plate rho = 1. E = 210.0 nu = 0.3 Plane_Stress = false ] -model phase_field_model [ - l0 = 0.1 - gc = 5.0e-3 - E = 210.0 - nu = 0.3 -] \ No newline at end of file +phasefield exponential [ + name = plate + E = 210.0 + nu = 0.3 + gc = 5e-3 + l0 = 0.1 +] diff --git a/test/test_model/test_phase_field_model/material_multiple.dat b/test/test_model/test_phase_field_model/material_multiple.dat new file mode 100644 index 000000000..6b1bbf28c --- /dev/null +++ b/test/test_model/test_phase_field_model/material_multiple.dat @@ -0,0 +1,34 @@ +material phasefield [ + name = plate + rho = 1. + E = 210.0 + nu = 0.3 + Plane_Stress = false +] + +material phasefield [ + name = rigid + rho = 1. + E = 210.0 + nu = 0.3 + Plane_Stress = false +] + + +phasefield exponential [ + name = plate + E = 210.0 + nu = 0.3 + gc = 5e-3 + l0 = 0.1 +] + + + +phasefield exponential [ + name = rigid + E = 210.0 + nu = 0.3 + gc = 5e-3 + l0 = 0.1 +] diff --git a/test/test_model/test_phase_field_model/test_multi_material.cc b/test/test_model/test_phase_field_model/test_multi_material.cc new file mode 100644 index 000000000..6509fffee --- /dev/null +++ b/test/test_model/test_phase_field_model/test_multi_material.cc @@ -0,0 +1,249 @@ +/** + * @file tets_phase_field_2d.cc + * + * @author Mohit Pundir + * + * @date creation: Mon Oct 1 2018 + * + * @brief test of the class PhaseFieldModel on the 2d square + * + * @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 "aka_common.hh" +#include "non_linear_solver.hh" +#include "solid_mechanics_model.hh" +#include "phase_field_model.hh" +#include "material.hh" +#include "material_phasefield.hh" +/* -------------------------------------------------------------------------- */ +#include +#include +/* -------------------------------------------------------------------------- */ + +using namespace akantu; +const UInt spatial_dimension = 2; + +/* -------------------------------------------------------------------------- */ +void applyDisplacement(SolidMechanicsModel &, Real &); +void computeStrainOnQuadPoints(SolidMechanicsModel &, PhaseFieldModel &, const GhostType &); +void computeDamageOnQuadPoints(SolidMechanicsModel &, PhaseFieldModel &, const GhostType &); +void gradUToEpsilon(const Matrix &, Matrix &); +/* -------------------------------------------------------------------------- */ + +int main(int argc, char *argv[]) { + + initialize("material_multiple.dat", argc, argv); + + Mesh mesh(spatial_dimension); + mesh.read("test_two_element.msh"); + + + + + SolidMechanicsModel model(mesh); + auto && mat_selector = std::make_shared>( + "physical_names", model); + model.setMaterialSelector(mat_selector); + + model.initFull(_analysis_method = _static); + + + PhaseFieldModel phase(mesh); + auto && selector = std::make_shared>( + "physical_names", phase); + phase.setPhaseFieldSelector(selector); + + phase.initFull(_analysis_method = _static); + + phase.setBaseName("multi_material"); + //model.addDumpField("stress"); + //model.addDumpField("grad_u"); + phase.addDumpField("damage"); + //model.addDumpFieldVector("displacement"); + //model.addDumpField("blocked_dofs"); + phase.dump(); + + UInt nbSteps = 10000; + Real increment = 2e-5; + + for (UInt s = 0; s < nbSteps; ++s) { + Real axial_strain = increment * s; + applyDisplacement(model, axial_strain); + + model.solveStep(); + model.assembleInternalForces(); + computeStrainOnQuadPoints(model, phase, _not_ghost); + + phase.solveStep(); + computeDamageOnQuadPoints(model, phase, _not_ghost); + + phase.dump(); + } + + finalize(); + + + + return EXIT_SUCCESS; + +} + + +/* -------------------------------------------------------------------------- */ +void applyDisplacement(SolidMechanicsModel & model, Real & increment) { + auto & displacement = model.getDisplacement(); + + auto & positions = model.getMesh().getNodes(); + auto & blocked_dofs = model.getBlockedDOFs(); + + + for (UInt n = 0; n < model.getMesh().getNbNodes(); ++n) { + if (positions(n, 1) == -1) { + displacement(n, 1) = 0; + blocked_dofs(n ,1) = true; + } + if (positions(n, 1) == 1) { + displacement(n, 1) = increment; + blocked_dofs(n ,1) = true; + } + displacement(n, 0) = 0; + blocked_dofs(n, 0) = true; + } +} + +/* -------------------------------------------------------------------------- */ +void computeStrainOnQuadPoints(SolidMechanicsModel & solid, PhaseFieldModel & phase, + const GhostType & ghost_type) { + + auto & mesh = solid.getMesh(); + + auto nb_materials = solid.getNbMaterials(); + auto nb_phasefields = phase.getNbPhaseFields(); + + AKANTU_DEBUG_ASSERT(nb_phasefields == nb_materials, + "The number of phasefields and materials should be equal" ); + + + for(auto index : arange(nb_materials)) { + auto & material = solid.getMaterial(index); + + for(auto index2 : arange(nb_phasefields)) { + auto & phasefield = phase.getPhaseField(index2); + + if(phasefield.getName() == material.getName()){ + + auto & strain_on_qpoints = phasefield.getStrain(); + auto & gradu_on_qpoints = material.getGradU(); + + for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { + auto & strain_on_qpoints_vect = strain_on_qpoints(type, ghost_type); + auto & gradu_on_qpoints_vect = gradu_on_qpoints(type, ghost_type); + for (auto && values: + zip(make_view(strain_on_qpoints_vect, spatial_dimension, spatial_dimension), + make_view(gradu_on_qpoints_vect, spatial_dimension, spatial_dimension))) { + auto & strain = std::get<0>(values); + auto & grad_u = std::get<1>(values); + gradUToEpsilon(grad_u, strain); + } + } + + break; + } + + } + } +} + + +/* -------------------------------------------------------------------------- */ +void computeDamageOnQuadPoints(SolidMechanicsModel & solid, PhaseFieldModel & phase, + const GhostType & ghost_type) { + + auto & fem = phase.getFEEngine(); + auto & mesh = phase.getMesh(); + + auto nb_materials = solid.getNbMaterials(); + auto nb_phasefields = phase.getNbPhaseFields(); + + AKANTU_DEBUG_ASSERT(nb_phasefields == nb_materials, + "The number of phasefields and materials should be equal" ); + + + for(auto index : arange(nb_materials)) { + auto & material = solid.getMaterial(index); + + for(auto index2 : arange(nb_phasefields)) { + auto & phasefield = phase.getPhaseField(index2); + + if(phasefield.getName() == material.getName()){ + + + switch (spatial_dimension) { + case 1: { + auto & mat = static_cast &>(material); + auto & solid_damage = mat.getDamage(); + auto & phase_damage = phasefield.getDamage(); + + for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { + auto & damage_on_qpoints_vect = solid_damage(type, ghost_type); + auto & phase_damage_on_qpoints_vect = phase_damage(type, ghost_type); + + fem.interpolateOnIntegrationPoints(phase.getDamage(), damage_on_qpoints_vect, + 1, type, ghost_type); + } + + break; + } + case 2: { + auto & mat = static_cast &>(material); + auto & solid_damage = mat.getDamage(); + auto & phase_damage = phasefield.getDamage(); + + for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { + auto & damage_on_qpoints_vect = solid_damage(type, ghost_type); + auto & phase_damage_on_qpoints_vect = phase_damage(type, ghost_type); + + fem.interpolateOnIntegrationPoints(phase.getDamage(), damage_on_qpoints_vect, + 1, type, ghost_type); + } + break; + } + default: + auto & mat = static_cast &>(material); + break; + } + + } + } + } + +} + + +/* -------------------------------------------------------------------------- */ +void gradUToEpsilon(const Matrix & grad_u, Matrix & epsilon) { + for (UInt i=0; i < spatial_dimension; ++i) { + for (UInt j = 0; j < spatial_dimension; ++j) + epsilon(i, j) = 0.5 * (grad_u(i, j) + grad_u(j, i)); + } +} diff --git a/test/test_model/test_phase_field_model/test_one_element.geo b/test/test_model/test_phase_field_model/test_one_element.geo index 840b30ca3..220cad3d9 100644 --- a/test/test_model/test_phase_field_model/test_one_element.geo +++ b/test/test_model/test_phase_field_model/test_one_element.geo @@ -1,17 +1,22 @@ // Gmsh project created on Fri Dec 28 23:39:32 2018 -Point(1) = {-0.5, -0.5, 0, 100.0}; -Point(2) = {0.5, -0.5, 0, 100.0}; -Point(3) = {0.5, 0.5, 0, 100.0}; -Point(4) = {-0.5, 0.5, 0, 100.0}; +h = 2; + +Point(1) = {-0.5, -0.5, 0, h}; +Point(2) = {0.5, -0.5, 0, h}; +Point(3) = {0.5, 0.5, 0, h}; +Point(4) = {-0.5, 0.5, 0, h}; Line(1) = {1, 2}; Line(2) = {2, 3}; Line(3) = {3, 4}; Line(4) = {4, 1}; Line Loop(1) = {3, 4, 1, 2}; Plane Surface(1) = {1}; Physical Surface("plate") = {1}; -Recombine Surface{1}; \ No newline at end of file +Transfinite Line {1, 2, 3, 4} = 2 Using Progression 1; +Transfinite Surface {1} = {1, 2, 3, 4}; + +Recombine Surface {1}; \ No newline at end of file diff --git a/test/test_model/test_phase_field_model/test_one_element.msh b/test/test_model/test_phase_field_model/test_one_element.msh new file mode 100644 index 000000000..8a4d09def --- /dev/null +++ b/test/test_model/test_phase_field_model/test_one_element.msh @@ -0,0 +1,36 @@ +$MeshFormat +4 0 8 +$EndMeshFormat +$PhysicalNames +1 +2 1 "plate" +$EndPhysicalNames +$Entities +4 4 1 0 +1 -0.5 -0.5 0 -0.5 -0.5 0 0 +2 0.5 -0.5 0 0.5 -0.5 0 0 +3 0.5 0.5 0 0.5 0.5 0 0 +4 -0.5 0.5 0 -0.5 0.5 0 0 +1 -0.5 -0.5 0 0.5 -0.5 0 0 2 1 -2 +2 0.5 -0.5 0 0.5 0.5 0 0 2 2 -3 +3 -0.5 0.5 0 0.5 0.5 0 0 2 3 -4 +4 -0.5 -0.5 0 -0.5 0.5 0 0 2 4 -1 +1 -0.5 -0.5 0 0.5 0.5 0 1 1 4 3 4 1 2 +$EndEntities +$Nodes +5 4 +1 0 0 1 +1 -0.5 -0.5 0 +2 0 0 1 +2 0.5 -0.5 0 +3 0 0 1 +3 0.5 0.5 0 +4 0 0 1 +4 -0.5 0.5 0 +1 2 0 0 +$EndNodes +$Elements +1 1 +1 2 3 1 +9 1 2 3 4 +$EndElements diff --git a/test/test_model/test_phase_field_model/test_phase_solid_coupling.cc b/test/test_model/test_phase_field_model/test_phase_solid_coupling.cc index 862c9e6c2..65e4c74a0 100644 --- a/test/test_model/test_phase_field_model/test_phase_solid_coupling.cc +++ b/test/test_model/test_phase_field_model/test_phase_solid_coupling.cc @@ -1,193 +1,267 @@ /** * @file tets_phase_field_2d.cc * * @author Mohit Pundir * * @date creation: Mon Oct 1 2018 * * @brief test of the class PhaseFieldModel on the 2d square * * @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 "aka_common.hh" #include "non_linear_solver.hh" #include "solid_mechanics_model.hh" #include "phase_field_model.hh" #include "material.hh" #include "material_phasefield.hh" /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ using namespace akantu; const UInt spatial_dimension = 2; /* -------------------------------------------------------------------------- */ -void applyDisplacement(SolidMechanicsModel &); +void applyDisplacement(SolidMechanicsModel &, Real &); void computeStrainOnQuadPoints(SolidMechanicsModel &, PhaseFieldModel &, const GhostType &); void computeDamageOnQuadPoints(SolidMechanicsModel &, PhaseFieldModel &, const GhostType &); void gradUToEpsilon(const Matrix &, Matrix &); /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { std::ofstream os("data.csv"); - os << "#disp stress damage" << std::endl; + os << "#strain stress damage analytical_sigma analytical_damage" << std::endl; initialize("material_coupling.dat", argc, argv); Mesh mesh(spatial_dimension); mesh.read("test_one_element.msh"); SolidMechanicsModel model(mesh); model.initFull(_analysis_method = _static); PhaseFieldModel phase(mesh); + auto && selector = std::make_shared>( + "physical_names", phase); + phase.setPhaseFieldSelector(selector); + phase.initFull(_analysis_method = _static); - model.setBaseName("phase_solid"); + phase.setBaseName("phase_solid"); model.addDumpField("stress"); model.addDumpField("grad_u"); + model.addDumpFieldVector("displacement"); model.addDumpField("damage"); - model.addDumpField("displacement"); model.dump(); UInt nbSteps = 1000; Real increment = 1e-4; - auto & damage = model.getMaterial(0).getArray("damage", _quadrangle_4); auto & stress = model.getMaterial(0).getArray("stress", _quadrangle_4); - - for (UInt s = 1; s < nbSteps; ++s) { - applyDisplacement(model); + auto & damage = model.getMaterial(0).getArray("damage", _quadrangle_4); + + Real analytical_damage{0.}; + Real analytical_sigma{0.}; + + auto & mat = model.getMaterial(0); + auto & phasefield = phase.getPhaseField(0); + + Real E = 210e3; + Real nu = 0.3; + Real c22 = E*(1-nu)/((1+nu)*(1-2*nu)); + + Real gc = 5; + Real l0 = 0.1; + + for (UInt s = 0; s < nbSteps; ++s) { + Real axial_strain = increment * s; + applyDisplacement(model, axial_strain); model.solveStep(); computeStrainOnQuadPoints(model, phase, _not_ghost); phase.solveStep(); computeDamageOnQuadPoints(model, phase, _not_ghost); - os << s*increment << " " << stress(0, 0) << " " << damage(0) << std::endl; + analytical_damage = axial_strain*axial_strain*c22/(gc/l0 + axial_strain*axial_strain*c22); + analytical_sigma = c22*axial_strain*(1-analytical_damage)*(1-analytical_damage); + os << axial_strain << " " << stress(0, 3) << " " << damage(0) << " " + << analytical_sigma << " " << analytical_damage << std::endl; + model.dump(); } os.close(); finalize(); + + return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ -void applyDisplacement(SolidMechanicsModel & model) { +void applyDisplacement(SolidMechanicsModel & model, Real & increment) { auto & displacement = model.getDisplacement(); auto & positions = model.getMesh().getNodes(); auto & blocked_dofs = model.getBlockedDOFs(); for (UInt n = 0; n < model.getMesh().getNbNodes(); ++n) { if (positions(n, 1) == -0.5) { displacement(n, 0) = 0; displacement(n, 1) = 0; blocked_dofs(n, 0) = true; blocked_dofs(n ,1) = true; } else { displacement(n, 0) = 0; - displacement(n, 1) += 1.e-4; + displacement(n, 1) = increment; blocked_dofs(n, 0) = true; blocked_dofs(n ,1) = true; } } } /* -------------------------------------------------------------------------- */ -void computeStrainOnQuadPoints(SolidMechanicsModel & solid, PhaseFieldModel & phase, const GhostType & ghost_type) { +void computeStrainOnQuadPoints(SolidMechanicsModel & solid, PhaseFieldModel & phase, + const GhostType & ghost_type) { auto & mesh = solid.getMesh(); - auto & strain_on_qpoints = phase.getStrain(); - auto & gradu_on_qpoints = solid.getMaterial(0).getGradU(); + auto nb_materials = solid.getNbMaterials(); + auto nb_phasefields = phase.getNbPhaseFields(); + + AKANTU_DEBUG_ASSERT(nb_phasefields == nb_materials, + "The number of phasefields and materials should be equal" ); + + + for(auto index : arange(nb_materials)) { + auto & material = solid.getMaterial(index); - for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { - auto & strain_on_qpoints_vect = strain_on_qpoints(type, ghost_type); - auto & gradu_on_qpoints_vect = gradu_on_qpoints(type, ghost_type); - for (auto && values: - zip(make_view(strain_on_qpoints_vect, spatial_dimension, spatial_dimension), + for(auto index2 : arange(nb_phasefields)) { + auto & phasefield = phase.getPhaseField(index2); + + if(phasefield.getName() == material.getName()){ + + auto & strain_on_qpoints = phasefield.getStrain(); + auto & gradu_on_qpoints = material.getGradU(); + + for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { + auto & strain_on_qpoints_vect = strain_on_qpoints(type, ghost_type); + auto & gradu_on_qpoints_vect = gradu_on_qpoints(type, ghost_type); + for (auto && values: + zip(make_view(strain_on_qpoints_vect, spatial_dimension, spatial_dimension), make_view(gradu_on_qpoints_vect, spatial_dimension, spatial_dimension))) { - auto & strain = std::get<0>(values); - auto & grad_u = std::get<1>(values); - gradUToEpsilon(grad_u, strain); + auto & strain = std::get<0>(values); + auto & grad_u = std::get<1>(values); + gradUToEpsilon(grad_u, strain); + } + } + + break; + } + } } } /* -------------------------------------------------------------------------- */ -void computeDamageOnQuadPoints(SolidMechanicsModel & solid, PhaseFieldModel & phase, const GhostType & ghost_type) { +void computeDamageOnQuadPoints(SolidMechanicsModel & solid, PhaseFieldModel & phase, + const GhostType & ghost_type) { auto & fem = phase.getFEEngine(); auto & mesh = phase.getMesh(); - switch (spatial_dimension) { - case 1: { - auto & mat = static_cast &>(solid.getMaterial(0)); - auto & damage = mat.getDamage(); - for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { - auto & damage_on_qpoints_vect = damage(type, ghost_type); - fem.interpolateOnIntegrationPoints(phase.getDamage(), damage_on_qpoints_vect, - 1, type, ghost_type); - } - - break; - } - case 2: { - auto & mat = static_cast &>(solid.getMaterial(0)); - auto & damage = mat.getDamage(); + auto nb_materials = solid.getNbMaterials(); + auto nb_phasefields = phase.getNbPhaseFields(); - for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { - auto & damage_on_qpoints_vect = damage(type, ghost_type); - fem.interpolateOnIntegrationPoints(phase.getDamage(), damage_on_qpoints_vect, - 1, type, ghost_type); + AKANTU_DEBUG_ASSERT(nb_phasefields == nb_materials, + "The number of phasefields and materials should be equal" ); + + + for(auto index : arange(nb_materials)) { + auto & material = solid.getMaterial(index); + + for(auto index2 : arange(nb_phasefields)) { + auto & phasefield = phase.getPhaseField(index2); + + if(phasefield.getName() == material.getName()){ + + + switch (spatial_dimension) { + case 1: { + auto & mat = static_cast &>(material); + auto & solid_damage = mat.getDamage(); + auto & phase_damage = phasefield.getDamage(); + + for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { + auto & damage_on_qpoints_vect = solid_damage(type, ghost_type); + auto & phase_damage_on_qpoints_vect = phase_damage(type, ghost_type); + + fem.interpolateOnIntegrationPoints(phase.getDamage(), damage_on_qpoints_vect, + 1, type, ghost_type); + } + + break; + } + case 2: { + auto & mat = static_cast &>(material); + auto & solid_damage = mat.getDamage(); + auto & phase_damage = phasefield.getDamage(); + + for (auto & type: mesh.elementTypes(spatial_dimension, ghost_type)) { + auto & damage_on_qpoints_vect = solid_damage(type, ghost_type); + auto & phase_damage_on_qpoints_vect = phase_damage(type, ghost_type); + + fem.interpolateOnIntegrationPoints(phase.getDamage(), damage_on_qpoints_vect, + 1, type, ghost_type); + } + break; + } + default: + auto & mat = static_cast &>(material); + break; + } + + } } - break; - } - default: - auto & mat = static_cast &>(solid.getMaterial(0)); - break; } } /* -------------------------------------------------------------------------- */ void gradUToEpsilon(const Matrix & grad_u, Matrix & epsilon) { for (UInt i=0; i < spatial_dimension; ++i) { for (UInt j = 0; j < spatial_dimension; ++j) epsilon(i, j) = 0.5 * (grad_u(i, j) + grad_u(j, i)); } } diff --git a/test/test_model/test_phase_field_model/test_phasefield_selector.cc b/test/test_model/test_phase_field_model/test_phasefield_selector.cc index 9f56214c3..3e5e26a65 100644 --- a/test/test_model/test_phase_field_model/test_phasefield_selector.cc +++ b/test/test_model/test_phase_field_model/test_phasefield_selector.cc @@ -1,66 +1,67 @@ /** * @file test_phasefield_selector.cc * * @author Mohit Pundir * * @date creation: Thu Jun 18 2020 * @date last modification: Thu Jun 18 2020 * * @brief Test for phasefield selector * * @section LICENSE * * Copyright (©) 2015-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 "aka_common.hh" #include "phase_field_model.hh" using namespace akantu; int main(int argc, char *argv[]){ initialize("phasefield_selector.dat", argc, argv); Math::setTolerance(1e-8); Mesh mesh(1); mesh.read("phasefield_selector.msh"); PhaseFieldModel model(mesh); auto && selector = std::make_shared>( "physical_names", model); model.setPhaseFieldSelector(selector); model.initFull(); PhaseField & chocolate = model.getPhaseField("chocolate"); PhaseField & chewing_gum = model.getPhaseField("chewing-gum"); PhaseField & candy = model.getPhaseField("candy"); UInt chocolate_element = chocolate.getElementFilter(_segment_2)(0, 0); UInt chewing_gum_element = chewing_gum.getElementFilter(_segment_2)(0, 0); UInt candy_element = candy.getElementFilter(_segment_2)(0, 0); if (chocolate_element != 0 || chewing_gum_element != 1 || candy_element != 2 ) { return EXIT_FAILURE; } return EXIT_SUCCESS; } + diff --git a/test/test_model/test_phase_field_model/test_solid_one_element.cc b/test/test_model/test_phase_field_model/test_solid_one_element.cc deleted file mode 100644 index e7aee5f20..000000000 --- a/test/test_model/test_phase_field_model/test_solid_one_element.cc +++ /dev/null @@ -1,97 +0,0 @@ -/** - * @file tets_phase_field_2d.cc - * - * @author Mohit Pundir - * - * @date creation: Mon Oct 1 2018 - * - * @brief test of the class PhaseFieldModel on the 2d square - * - * @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 "non_linear_solver.hh" -#include "solid_mechanics_model.hh" -/* -------------------------------------------------------------------------- */ -#include -/* -------------------------------------------------------------------------- */ - -using namespace akantu; -const UInt spatial_dimension = 2; -/* -------------------------------------------------------------------------- */ -void applyDisplacement(SolidMechanicsModel &); -/* -------------------------------------------------------------------------- */ - -int main(int argc, char *argv[]) { - - initialize("material_solid.dat", argc, argv); - - Mesh mesh(spatial_dimension); - mesh.read("test_one_element.msh"); - - SolidMechanicsModel model(mesh); - model.initFull(_analysis_method = _static); - - model.setBaseName("solid_one_element"); - model.addDumpField("stress"); - model.addDumpField("grad_u"); - model.addDumpField("displacement"); - model.dump(); - - UInt nbSteps = 1000; - - for (UInt s = 0; s < nbSteps; ++s) { - applyDisplacement(model); - model.solveStep(); - model.dump(); - } - - finalize(); - - return EXIT_SUCCESS; - -} - - -/* -------------------------------------------------------------------------- */ -void applyDisplacement(SolidMechanicsModel & model) { - auto & displacement = model.getDisplacement(); - - auto & positions = model.getMesh().getNodes(); - auto & blocked_dofs = model.getBlockedDOFs(); - - - for (UInt n = 0; n < model.getMesh().getNbNodes(); ++n) { - if (positions(n, 1) == -0.5) { - displacement(n, 0) = 0; - displacement(n, 1) = 0; - blocked_dofs(n, 0) = true; - blocked_dofs(n ,1) = true; - } - else { - displacement(n, 0) = 0; - displacement(n, 1) += 1.e-4; - blocked_dofs(n, 0) = true; - blocked_dofs(n ,1) = true; - } - } -} diff --git a/test/test_model/test_phase_field_model/test_two_element.geo b/test/test_model/test_phase_field_model/test_two_element.geo new file mode 100644 index 000000000..cb7f4bc98 --- /dev/null +++ b/test/test_model/test_phase_field_model/test_two_element.geo @@ -0,0 +1,37 @@ +h = 2; + +Point(1) = {-1, -1, 0, h}; +Point(2) = {0, -1, 0, h}; +Point(3) = {0, 0, 0, h}; +Point(4) = {-1, 0, 0, h}; + +Point(7) = {0, 1, 0, h}; +Point(8) = {-1, 1, 0, h}; + + +Line(1) = {1, 2}; +Line(2) = {2, 3}; +Line(3) = {3, 4}; +Line(4) = {4, 1}; + +Line(7) = {3, 7}; +Line(8) = {7, 8}; +Line(9) = {8, 4}; + +Line Loop(1) = {3, 4, 1, 2}; +Line Loop(2) = {7, 8, 9, -3}; + + +Plane Surface(1) = {1}; +Physical Surface("plate") = {1}; + + +Plane Surface(2) = {2}; +Physical Surface("rigid") = {2}; + +Transfinite Line {1, 2, 3, 4, 7, 8, 9} = 2 Using Progression 1; + +//Transfinite Surface {1} = {1, 2, 3, 4}; +//Transfinite Surface {2} = {7, 8, 9, -3}; + +Recombine Surface{1, 2};g \ No newline at end of file diff --git a/test/test_model/test_phase_field_model/test_two_element.msh b/test/test_model/test_phase_field_model/test_two_element.msh new file mode 100644 index 000000000..cbcef7885 --- /dev/null +++ b/test/test_model/test_phase_field_model/test_two_element.msh @@ -0,0 +1,50 @@ +$MeshFormat +4 0 8 +$EndMeshFormat +$PhysicalNames +2 +2 1 "plate" +2 2 "rigid" +$EndPhysicalNames +$Entities +6 7 2 0 +1 -1 -1 0 -1 -1 0 0 +2 0 -1 0 0 -1 0 0 +3 0 0 0 0 0 0 0 +4 -1 0 0 -1 0 0 0 +7 0 1 0 0 1 0 0 +8 -1 1 0 -1 1 0 0 +1 -1 -1 0 0 -1 0 0 2 1 -2 +2 0 -1 0 0 0 0 0 2 2 -3 +3 -1 0 0 0 0 0 0 2 3 -4 +4 -1 -1 0 -1 0 0 0 2 4 -1 +7 0 0 0 0 1 0 0 2 3 -7 +8 -1 1 0 0 1 0 0 2 7 -8 +9 -1 0 0 -1 1 0 0 2 8 -4 +1 -1 -1 0 0 0 0 1 1 4 3 4 1 2 +2 -1 0 0 0 1 0 1 2 4 7 8 9 -3 +$EndEntities +$Nodes +8 6 +1 0 0 1 +1 -1 -1 0 +2 0 0 1 +2 0 -1 0 +3 0 0 1 +3 0 0 0 +4 0 0 1 +4 -1 0 0 +7 0 0 1 +5 0 1 0 +8 0 0 1 +6 -1 1 0 +1 2 0 0 +2 2 0 0 +$EndNodes +$Elements +2 2 +1 2 3 1 +14 1 2 3 4 +2 2 3 1 +15 6 4 3 5 +$EndElements diff --git a/test/test_python_interface/CMakeLists.txt b/test/test_python_interface/CMakeLists.txt index 6bc80a4bf..ca8b72841 100644 --- a/test/test_python_interface/CMakeLists.txt +++ b/test/test_python_interface/CMakeLists.txt @@ -1,52 +1,55 @@ #=============================================================================== # @file CMakeLists.txt # # @author Fabian Barras # @author Lucas Frerot # # @date creation: Fri Sep 03 2010 # @date last modification: Mon Feb 05 2018 # # @brief Python Interface tests # # @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 . # #=============================================================================== -get_target_property(_srcs py11_akantu SOURCES) -foreach(_src ${_srcs}) - list(APPEND py11_akantu_test_common_SRCS ${PROJECT_SOURCE_DIR}/python/${_src}) -endforeach() +#get_target_property(_srcs py11_akantu SOURCES) +#foreach(_src ${_srcs}) +# list(APPEND py11_akantu_test_common_SRCS ${PROJECT_SOURCE_DIR}/python/${_src}) +#endforeach() +# +#akantu_pybind11_add_module(py11_akantu_test_common MODULE +# test_common.cc +# ${py11_akantu_test_common_SRCS}) +#target_link_libraries(py11_akantu_test_common +# PRIVATE $) +#target_include_directories(py11_akantu_test_common +# PRIVATE $) +# -akantu_pybind11_add_module(py11_akantu_test_common MODULE - test_common.cc - ${py11_akantu_test_common_SRCS}) -target_link_libraries(py11_akantu_test_common - PRIVATE $) -target_include_directories(py11_akantu_test_common - PRIVATE $) +akantu_pybind11_add_module(py11_akantu_test_common MODULE test_common.cc ${AKANTU_PY11_SRCS}) add_mesh(mesh_dcb_2d mesh_dcb_2d.geo 2 2) register_test(test_python_interface SCRIPT test_pybind.py PYTHON FILES_TO_COPY elastic.dat DEPENDS mesh_dcb_2d py11_akantu_test_common PACKAGE python_interface )