branch: master commit 1af40fc293dd133a9dfdec62fb84646c9976241b Author: Konstantinos Poulios <logar...@gmail.com> Date: Sat Mar 23 07:39:01 2019 +0100
Increase constness in model::var_description --- src/getfem/getfem_models.h | 40 ++++++++++++++-------------- src/getfem_models.cc | 65 +++++++++++++++++++++++----------------------- 2 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/getfem/getfem_models.h b/src/getfem/getfem_models.h index 2d884ad..c77fca5 100644 --- a/src/getfem/getfem_models.h +++ b/src/getfem/getfem_models.h @@ -146,22 +146,22 @@ namespace getfem { struct var_description { - bool is_variable; // This is a variable or a parameter. - bool is_disabled; // For a variable, to be solved or not - bool is_complex; // The variable is complex numbers + const bool is_variable; // This is a variable or a parameter. + bool is_disabled; // For a variable, to be solved or not + const bool is_complex; // The variable is complex numbers bool is_affine_dependent; // The variable depends in an affine way // to another variable. - bool is_fem_dofs; // The variable is the dofs of a fem + const bool is_fem_dofs; // The variable is the dofs of a fem size_type n_iter; // Number of versions of the variable stored. size_type n_temp_iter; // Number of additional temporary versions size_type default_iter; // default iteration number. ptime_scheme ptsc; // For optional time integration scheme - var_description_filter filter; // Version of an optional filter + const var_description_filter filter; // Version of an (optional) filter // on the dofs - size_type filter_region; // Optional region for the filter - std::string filter_var; // Optional variable name for the filter + const size_type filter_region; // Optional region for the filter + const std::string filter_var; // Optional variable name for the filter const mesh_im *filter_mim; // Optional integration method for the filter // fem or im_data description of the variable @@ -190,26 +190,22 @@ namespace getfem { std::string org_name; // Name of the original variable for affine // dependent variables - size_type qdim() const { return qdims.total_size(); } - - var_description(bool is_var = false, bool is_com = false, - bool is_fem = false, size_type n_it = 1, + var_description(bool is_var = false, bool is_compl = false, + const mesh_fem *mf_ = 0, const im_data *imd_ = 0, + size_type n_it = 1, var_description_filter filter_ = VDESCRFILTER_NO, - const mesh_fem *mf_ = 0, size_type filter_reg = size_type(-1), - bgeot::multi_index qdims_ = bgeot::multi_index(), const std::string &filter_var_ = std::string(""), - const mesh_im *filter_mim_ = 0, const im_data *imd_ = 0) - : is_variable(is_var), is_disabled(false), is_complex(is_com), - is_affine_dependent(false), is_fem_dofs(is_fem), + const mesh_im *filter_mim_ = 0) + : is_variable(is_var), is_disabled(false), is_complex(is_compl), + is_affine_dependent(false), + is_fem_dofs(mf_ != 0), n_iter(std::max(size_type(1), n_it)), n_temp_iter(0), default_iter(0), ptsc(0), filter(filter_), filter_region(filter_reg), filter_var(filter_var_), - filter_mim(filter_mim_), - mf(mf_), imd(imd_), qdims(qdims_), v_num(0), - v_num_data(n_iter, act_counter()), I(0,0), - alpha(1) { - + filter_mim(filter_mim_), mf(mf_), imd(imd_), qdims(), + v_num(0), v_num_data(n_iter, act_counter()), I(0,0), alpha(1) + { if (filter != VDESCRFILTER_NO && mf != 0) partial_mf = std::make_shared<partial_mesh_fem>(*mf); // v_num_data = v_num; @@ -217,6 +213,8 @@ namespace getfem { GMM_ASSERT1(qdim(), "Attempt to create a null size variable"); } + size_type qdim() const { return qdims.total_size(); } + // add a temporary version for time integration schemes. Automatically // set the default iter to it. id_num is an identifier. Do not add // the version if a temporary already exist with this identifier. diff --git a/src/getfem_models.cc b/src/getfem_models.cc index 8a75b86..0aaa403 100644 --- a/src/getfem_models.cc +++ b/src/getfem_models.cc @@ -667,23 +667,21 @@ namespace getfem { void model::add_fixed_size_variable(const std::string &name, size_type size, size_type niter) { - check_name_validity(name); - variables[name] = var_description(true, is_complex(), false, niter); - GMM_ASSERT1(size, "Variable of null size are not allowed"); - variables[name].qdims[0] = size; - act_size_to_be_done = true; - variables[name].set_size(); + bgeot::multi_index sizes(1); + sizes[0] = size; + add_fixed_size_variable(name, sizes, niter); } void model::add_fixed_size_variable(const std::string &name, const bgeot::multi_index &sizes, size_type niter) { check_name_validity(name); - variables[name] = var_description(true, is_complex(), false, niter, - VDESCRFILTER_NO, 0, size_type(-1), - sizes); + variables.emplace(name, var_description(true, is_complex(), 0, 0, niter)); + variables[name].qdims = sizes; act_size_to_be_done = true; variables[name].set_size(); + GMM_ASSERT1(variables[name].qdim(), + "Variables of null size are not allowed"); } void model::resize_fixed_size_variable(const std::string &name, @@ -719,7 +717,7 @@ namespace getfem { const bgeot::multi_index &sizes, size_type niter) { check_name_validity(name); - variables[name] = var_description(false, is_complex(), false, niter); + variables.emplace(name, var_description(false, is_complex(), 0, 0, niter)); variables[name].qdims = sizes; GMM_ASSERT1(variables[name].qdim(), "Data of null size are not allowed"); variables[name].set_size(); @@ -755,20 +753,20 @@ namespace getfem { gmm::copy(t.as_vector(), set_complex_variable(name)); } - void model::add_im_data(const std::string &name, const im_data &im_data, + void model::add_im_data(const std::string &name, const im_data &imd, size_type niter) { check_name_validity(name); - variables[name] = var_description(false, is_complex(), false, niter); - variables[name].imd = &im_data; + variables.emplace(name, + var_description(false, is_complex(), 0, &imd, niter)); variables[name].set_size(); - add_dependency(im_data); + add_dependency(imd); } void model::add_fem_variable(const std::string &name, const mesh_fem &mf, size_type niter) { check_name_validity(name); - variables[name] = var_description(true, is_complex(), true, niter, - VDESCRFILTER_NO, &mf); + variables.emplace(name, var_description(true, is_complex(), &mf, 0, niter, + VDESCRFILTER_NO)); variables[name].set_size(); add_dependency(mf); act_size_to_be_done = true; @@ -779,8 +777,8 @@ namespace getfem { const mesh_fem &mf, size_type region, size_type niter) { check_name_validity(name); - variables[name] = var_description(true, is_complex(), true, niter, - VDESCRFILTER_REGION, &mf, region); + variables.emplace(name, var_description(true, is_complex(), &mf, 0, niter, + VDESCRFILTER_REGION, region)); variables[name].set_size(); act_size_to_be_done = true; add_dependency(mf); @@ -793,7 +791,7 @@ namespace getfem { VAR_SET::const_iterator it = find_variable(org_name); GMM_ASSERT1(it->second.is_variable && !(it->second.is_affine_dependent), "The original variable should be a variable"); - variables[name] = variables[org_name]; + variables.emplace(name, variables[org_name]); variables[name].is_affine_dependent = true; variables[name].org_name = org_name; variables[name].alpha = alpha; @@ -803,8 +801,8 @@ namespace getfem { void model::add_fem_data(const std::string &name, const mesh_fem &mf, dim_type qdim, size_type niter) { check_name_validity(name); - variables[name] = var_description(false, is_complex(), true, niter, - VDESCRFILTER_NO, &mf); + variables.emplace(name, var_description(false, is_complex(), &mf, 0, niter, + VDESCRFILTER_NO)); variables[name].qdims[0] = qdim; GMM_ASSERT1(qdim, "Data of null size are not allowed"); variables[name].set_size(); @@ -814,8 +812,8 @@ namespace getfem { void model::add_fem_data(const std::string &name, const mesh_fem &mf, const bgeot::multi_index &sizes, size_type niter) { check_name_validity(name); - variables[name] = var_description(false, is_complex(), true, niter, - VDESCRFILTER_NO, &mf); + variables.emplace(name, var_description(false, is_complex(), &mf, 0, niter, + VDESCRFILTER_NO)); variables[name].qdims = sizes; GMM_ASSERT1(variables[name].qdim(), "Data of null size are not allowed"); variables[name].set_size(); @@ -826,9 +824,9 @@ namespace getfem { const std::string &primal_name, size_type niter) { check_name_validity(name); - variables[name] = var_description(true, is_complex(), true, niter, - VDESCRFILTER_CTERM, &mf, 0, - bgeot::multi_index(), primal_name); + variables.emplace(name, var_description(true, is_complex(), &mf, 0, niter, + VDESCRFILTER_CTERM, size_type(-1), + primal_name)); variables[name].set_size(); act_size_to_be_done = true; add_dependency(mf); @@ -838,21 +836,22 @@ namespace getfem { size_type region, const std::string &primal_name, size_type niter) { check_name_validity(name); - variables[name] = var_description(true, is_complex(), true, niter, - VDESCRFILTER_REGION_CTERM, &mf, region, - bgeot::multi_index(), primal_name); + variables.emplace(name, var_description(true, is_complex(), &mf, 0, niter, + VDESCRFILTER_REGION_CTERM, region, + primal_name)); variables[name].set_size(); act_size_to_be_done = true; add_dependency(mf); } void model::add_multiplier(const std::string &name, const mesh_fem &mf, - const std::string &primal_name,const mesh_im &mim, + const std::string &primal_name, + const mesh_im &mim, size_type region, size_type niter) { check_name_validity(name); - variables[name] = var_description(true, is_complex(), true, niter, - VDESCRFILTER_INFSUP, &mf, region, - bgeot::multi_index(), primal_name, &mim); + variables.emplace(name, var_description(true, is_complex(), &mf, 0, niter, + VDESCRFILTER_INFSUP, region, + primal_name, &mim)); variables[name].set_size(); act_size_to_be_done = true; add_dependency(mf);