[Getfem-commits] [getfem-commits] branch devel-logari81-internal-variables updated: Add unit test for internal variable condensation

2020-02-01 Thread Konstantinos Poulios via Getfem-commits
This is an automated email from the git hooks/post-receive script.

logari81 pushed a commit to branch devel-logari81-internal-variables
in repository getfem.

The following commit(s) were added to 
refs/heads/devel-logari81-internal-variables by this push:
 new 9d1c444  Add unit test for internal variable condensation
9d1c444 is described below

commit 9d1c4449796fe7b3c3adabeed57977c5d6ac7507
Author: Konstantinos Poulios 
AuthorDate: Sat Feb 1 11:28:19 2020 +0100

Add unit test for internal variable condensation
---
 tests/Makefile.am  |   4 +
 tests/test_condensation.cc | 184 +
 tests/test_condensation.pl | 105 ++
 3 files changed, 293 insertions(+)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index ba8b7a3..296934f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,6 +45,7 @@ check_PROGRAMS =   \
test_assembly_assignment   \
test_interpolated_fem  \
test_internal_variables\
+   test_condensation  \
test_range_basis   \
laplacian  \
laplacian_with_bricks  \
@@ -100,6 +101,7 @@ geo_trans_inv_SOURCES = geo_trans_inv.cc
 test_int_set_SOURCES = test_int_set.cc
 test_interpolated_fem_SOURCES = test_interpolated_fem.cc
 test_internal_variables_SOURCES = test_internal_variables.cc
+test_condensation_SOURCES = test_condensation.cc
 test_tree_sorted_SOURCES = test_tree_sorted.cc
 test_mat_elem_SOURCES = test_mat_elem.cc
 test_slice_SOURCES = test_slice.cc
@@ -141,6 +143,7 @@ TESTS = \
test_assembly_assignment.pl   \
test_interpolated_fem.pl  \
test_internal_variables.pl\
+   test_condensation.pl  \
test_range_basis.pl   \
laplacian.pl  \
laplacian_with_bricks.pl  \
@@ -182,6 +185,7 @@ EXTRA_DIST =
\
test_int_set.pl \
test_interpolated_fem.pl\
test_internal_variables.pl  \
+   test_condensation.pl\
test_slice.pl   \
test_mesh_im_level_set.pl   \
thermo_elasticity_electrical_coupling.pl\
diff --git a/tests/test_condensation.cc b/tests/test_condensation.cc
new file mode 100644
index 000..2a3ec22
--- /dev/null
+++ b/tests/test_condensation.cc
@@ -0,0 +1,184 @@
+/*===
+
+ Copyright (C) 2019-2020 Konstantinos Poulios.
+
+ This file is a part of GetFEM++
+
+ GetFEM++  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 along with the GCC Runtime Library
+ Exception either version 3.1 or (at your option) any later version.
+ This program  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 and GCC Runtime Library Exception for more details.
+ You  should  have received a copy of the GNU Lesser General Public License
+ along  with  this program;  if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+
+===*/
+#include "getfem/getfem_regular_meshes.h"
+#include "getfem/getfem_export.h"
+#include "getfem/getfem_model_solvers.h"
+
+using bgeot::dim_type;
+using bgeot::size_type;
+using bgeot::scalar_type;
+using bgeot::base_node;
+
+static bool debug=false;
+
+int main(int argc, char *argv[]) {
+
+  gmm::set_traces_level(1);
+
+  bgeot::md_param PARAM;
+  PARAM.add_int_param("NX", 1);
+  PARAM.add_int_param("NY", 1);
+  PARAM.add_int_param("FEM_ORDER", 1);
+  PARAM.add_int_param("IM_ORDER", 1);
+  PARAM.add_int_param("DIFFICULTY", 0);
+  PARAM.read_command_line(argc, argv);
+  size_type NX = PARAM.int_value("NX", "Number of elements in X direction");
+  size_type NY = PARAM.int_value("NY", "Number of elements in Y direction");
+  dim_type FEM_ORDER = dim_type(PARAM.int_value("FEM_ORDER", "Degree of finite 
element basis"));
+  dim_type IM_ORDER = dim_type(PARAM.int_value("IM_ORDER", "Degree of 
integration method"));
+  size_type DIFFICULTY = PARAM.int_value("DIFFICULTY", "Difficulty of test");
+
+  getfem::mesh m;
+  getfem::regular_unit_mesh(m, {NX, NY}, 
bgeot::geometric_trans_descriptor("GT_QK(2, 2)"));
+
+  getfem::mesh_region outer_faces;
+  getfem::outer_faces_of_mesh(m, outer_faces);
+  m.region(98) = 

[Getfem-commits] [getfem-commits] branch devel-logari81-internal-variables updated: Fix model class for internal variable condensation

2020-02-01 Thread Konstantinos Poulios via Getfem-commits
This is an automated email from the git hooks/post-receive script.

logari81 pushed a commit to branch devel-logari81-internal-variables
in repository getfem.

The following commit(s) were added to 
refs/heads/devel-logari81-internal-variables by this push:
 new d7d1e07  Fix model class for internal variable condensation
d7d1e07 is described below

commit d7d1e07384e555389d3c1e7cdf46bc970cf5a4de
Author: Konstantinos Poulios 
AuthorDate: Sat Feb 1 11:23:55 2020 +0100

Fix model class for internal variable condensation
---
 src/getfem_models.cc | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/getfem_models.cc b/src/getfem_models.cc
index d509046..14e2673 100644
--- a/src/getfem_models.cc
+++ b/src/getfem_models.cc
@@ -2597,8 +2597,11 @@ namespace getfem {
   if (version & BUILD_RHS) approx_external_load_ += brick.external_load;
 }
 
-if (gmm::vect_size(full_rrhs)) { // i.e. if has_internal_variables()
+if (version & BUILD_RHS && version & BUILD_WITH_INTERNAL) {
+  GMM_ASSERT1(gmm::vect_size(full_rrhs) > 0 && has_internal_variables(),
+  "Internal error");
   gmm::sub_interval IP(0,gmm::vect_size(rrhs));
+  gmm::fill(full_rrhs, 0.);
   gmm::copy(rrhs, gmm::sub_vector(full_rrhs, IP)); // TICTIC
 }
 
@@ -2656,14 +2659,12 @@ namespace getfem {
 if (with_internal) { // Condensation reads from/writes to rhs
   gmm::copy(res0_distro.get(), res1_distro.get());
   gmm::add(gmm::scaled(full_rrhs, scalar_type(-1)),
-   res1_distro.get()); // TIC: initial value residual=-rhs
+   res1_distro.get()); // initial value residual=-rhs 
(actually only the internal variables residual is needed)
   workspace.set_assembled_vector(res1_distro);
   workspace.set_internal_coupling_matrix(intern_mat_distro);
 }
 workspace.set_assembled_matrix(tangent_matrix_distro);
 workspace.assembly(2, with_internal);
-if (with_internal) // TOC: diff from initial value, hack to make 
OMP work
-  gmm::add(full_rrhs, res1_distro.get());
   ) // end GETFEM_OMP_PARALLEL
 } // end of res0_distro scope
 else { // only BUILD_MATRIX
@@ -2672,14 +2673,12 @@ namespace getfem {
 add_assignments_and_expressions_to_workspace(workspace);
 if (with_internal) { // Condensation reads from/writes to rhs
   gmm::copy(gmm::scaled(full_rrhs, scalar_type(-1)),
-res1_distro.get()); // TIC: initial value residual=-rhs
+res1_distro.get()); // initial value residual=-rhs 
(actually only the internal variables residual is needed)
   workspace.set_assembled_vector(res1_distro);
   workspace.set_internal_coupling_matrix(intern_mat_distro);
 }
 workspace.set_assembled_matrix(tangent_matrix_distro);
 workspace.assembly(2, with_internal);
-if (with_internal) // TOC: diff from initial value, hack to make 
OMP work
-  gmm::add(full_rrhs, res1_distro.get());
   ) // end GETFEM_OMP_PARALLEL
 }
   } // end of tangent_matrix_distro, intern_mat_distro, res1_distro scope