[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] (no subject)
From: |
Konstantinos Poulios |
Subject: |
[Getfem-commits] (no subject) |
Date: |
Fri, 11 Jan 2019 04:23:12 -0500 (EST) |
branch: integration-point-variables
commit 875701396861fbf8202dffa4875e8ec914c92230
Author: Konstantinos Poulios <address@hidden>
Date: Fri Jan 11 10:22:58 2019 +0100
Stricter constness in model::var_description and tidying up
---
src/getfem/getfem_models.h | 92 ++++++++++++++++----------------
src/getfem_models.cc | 127 +++++++++++++++++++++------------------------
2 files changed, 107 insertions(+), 112 deletions(-)
diff --git a/src/getfem/getfem_models.h b/src/getfem/getfem_models.h
index 5704d50..5b99dec 100644
--- a/src/getfem/getfem_models.h
+++ b/src/getfem/getfem_models.h
@@ -146,25 +146,28 @@ 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
- 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
- var_description_filter filter; // A filter on the dofs is applied or not.
- 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
-
- // fem description of the variable
- const mesh_fem *mf; // Main fem of the variable.
- size_type m_region; // Optional region for the filter
- const mesh_im *mim; // Optional integration method for the filter
- ppartial_mesh_fem partial_mf; // Filter with respect to mf.
- std::string filter_var; // Optional variable name for the filter
+ 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.
+ 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
+
+ const var_description_filter filter; // Version of an (optional) filter
+ // on the dofs
+ 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
+ const mesh_fem *mf; // Main fem of the variable.
+ ppartial_mesh_fem partial_mf; // Filter with respect to mf.
+ const im_data *imd; // im data description
bgeot::multi_index qdims; // For data having a qdim != of the fem
// (dim per dof for dof data)
@@ -185,29 +188,25 @@ namespace getfem {
model_complex_plain_vector affine_complex_value;
scalar_type alpha; // Factor for the affine dependent variables
std::string org_name; // Name of the original variable for affine
- // dependent variables
-
- // im data description
- const im_data *pim_data;
-
- 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_filter fil = VDESCRFILTER_NO,
- const mesh_fem *mmf = 0,
- size_type m_reg = size_type(-1),
- bgeot::multi_index qdims_ = bgeot::multi_index(),
- const std::string &filter_v = std::string(""),
- const mesh_im *mim_ = 0, const im_data *pimd = 0)
- : is_variable(is_var), is_disabled(false), is_complex(is_com),
- is_affine_dependent(false), is_fem_dofs(is_fem), filter(fil),
+ // dependent variables
+
+ 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,
+ size_type filter_reg = size_type(-1),
+ const std::string &filter_var_ = std::string(""),
+ 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), mf(mmf), m_region(m_reg), mim(mim_),
- filter_var(filter_v), qdims(qdims_), v_num(0),
- v_num_data(n_iter, act_counter()), I(0,0),
- alpha(1), pim_data(pimd) {
-
+ default_iter(0), ptsc(0),
+ filter(filter_), filter_region(filter_reg), filter_var(filter_var_),
+ 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;
@@ -215,6 +214,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.
@@ -228,10 +229,11 @@ namespace getfem {
}
const mesh_fem *passociated_mf() const {
- if (!is_fem_dofs)
+ if (is_fem_dofs)
+ return (filter == VDESCRFILTER_NO || partial_mf.get() == 0)
+ ? mf : partial_mf.get();
+ else
return 0;
- return (filter == VDESCRFILTER_NO || partial_mf.get() == 0)
- ? mf : partial_mf.get();
}
size_type size() const // Should control that the variable is
@@ -239,7 +241,7 @@ namespace getfem {
{ return is_complex ? complex_value[0].size() : real_value[0].size(); }
void set_size();
- };
+ }; // struct var_description
public:
diff --git a/src/getfem_models.cc b/src/getfem_models.cc
index 938aa31..965c746 100644
--- a/src/getfem_models.cc
+++ b/src/getfem_models.cc
@@ -51,8 +51,9 @@ namespace getfem {
v_num_var_iter.resize(n_iter);
v_num_iter.resize(n_iter);
size_type s = is_fem_dofs ? passociated_mf()->nb_dof()
- : (pim_data ?
- (pim_data->nb_filtered_index() * pim_data->nb_tensor_elem()) : 1);
+ : (imd ? imd->nb_filtered_index()
+ * imd->nb_tensor_elem()
+ : 1);
s *= qdim();
for (size_type i = 0; i < n_iter; ++i)
if (is_complex)
@@ -261,13 +262,13 @@ namespace getfem {
bool model::is_im_data(const std::string &name) const {
auto it = find_variable(no_old_prefix_name(name));
- return (it->second.pim_data != 0);
+ return (it->second.imd != 0);
}
const im_data *
model::pim_data_of_variable(const std::string &name) const {
auto it = find_variable(no_old_prefix_name(name));
- return it->second.pim_data;
+ return it->second.imd;
}
const gmm::uint64_type &
@@ -369,8 +370,8 @@ namespace getfem {
break;
case VDESCRFILTER_REGION:
if (vdescr.v_num < vdescr.mf->version_number()) {
- dal::bit_vector dor
- = vdescr.mf->dof_on_region(vdescr.m_region);
+ dal::bit_vector
+ dor = vdescr.mf->dof_on_region(vdescr.filter_region);
vdescr.partial_mf->adapt(dor);
vdescr.set_size();
vdescr.v_num = act_counter();
@@ -380,9 +381,8 @@ namespace getfem {
}
}
- if (vdescr.pim_data != 0
- && vdescr.v_num < vdescr.pim_data->version_number()) {
- // const im_data *pimd = vdescr.pim_data;
+ if (vdescr.imd != 0
+ && vdescr.v_num < vdescr.imd->version_number()) {
vdescr.set_size();
vdescr.v_num = act_counter();
}
@@ -540,9 +540,9 @@ namespace getfem {
GMM_WARNING1("No term found to filter multiplier " << multname
<< ". Variable is cancelled");
} else if (multdescr.filter & VDESCRFILTER_INFSUP) {
- mesh_region rg(multdescr.m_region);
- multdescr.mim->linked_mesh().intersect_with_mpi_region(rg);
- asm_mass_matrix(MM, *(multdescr.mim), vdescr.associated_mf(),
+ mesh_region rg(multdescr.filter_region);
+ multdescr.filter_mim->linked_mesh().intersect_with_mpi_region(rg);
+ asm_mass_matrix(MM, *(multdescr.filter_mim), vdescr.associated_mf(),
*(multdescr.mf), rg);
}
@@ -569,7 +569,7 @@ namespace getfem {
for (const size_type &icol : columns)
kept.add(icol);
if (multdescr.filter & VDESCRFILTER_REGION)
- kept &= multdescr.mf->dof_on_region(multdescr.m_region);
+ kept &= multdescr.mf->dof_on_region(multdescr.filter_region);
multdescr.partial_mf->adapt(kept);
multdescr.set_size();
multdescr.v_num = act_counter();
@@ -595,7 +595,7 @@ namespace getfem {
for (const size_type &icol : glob_columns)
if (icol >= s && icol < s + nbdof) kept.add(icol-s);
if (multdescr.filter & VDESCRFILTER_REGION)
- kept &= multdescr.mf->dof_on_region(multdescr.m_region);
+ kept &= multdescr.mf->dof_on_region(multdescr.filter_region);
multdescr.partial_mf->adapt(kept);
multdescr.set_size();
multdescr.v_num = act_counter();
@@ -641,7 +641,7 @@ namespace getfem {
if (it->second.is_variable &&
is_disabled_variable(it->first)) ost << "\t (disabled)";
else ost << "\t ";
- if (it->second.pim_data != 0) ost << "\t (is im_data)";
+ if (it->second.imd != 0) ost << "\t (is im_data)";
if (it->second.is_affine_dependent) ost << "\t (is affine dependent)";
ost << endl;
}
@@ -680,32 +680,30 @@ 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,
size_type size) {
GMM_ASSERT1(!(variables[name].is_fem_dofs),
"Cannot explicitly resize a fem variable or data");
- GMM_ASSERT1(variables[name].pim_data == 0,
+ GMM_ASSERT1(variables[name].imd == 0,
"Cannot explicitly resize an im data");
- GMM_ASSERT1(size, "Variable of null size are not allowed");
+ GMM_ASSERT1(size, "Variables of null size are not allowed");
variables[name].qdims.resize(1);
variables[name].qdims[0] = size;
variables[name].set_size();
@@ -715,7 +713,7 @@ namespace getfem {
const bgeot::multi_index &sizes) {
GMM_ASSERT1(!(variables[name].is_fem_dofs),
"Cannot explicitly resize a fem variable or data");
- GMM_ASSERT1(variables[name].pim_data == 0,
+ GMM_ASSERT1(variables[name].imd == 0,
"Cannot explicitly resize an im data");
variables[name].qdims = sizes;
variables[name].set_size();
@@ -723,18 +721,16 @@ namespace getfem {
void model::add_fixed_size_data(const std::string &name, size_type size,
size_type niter) {
- check_name_validity(name);
- variables[name] = var_description(false, is_complex(), false, niter);
- GMM_ASSERT1(size, "Data of null size are not allowed");
- variables[name].qdims[0] = size;
- variables[name].set_size();
+ bgeot::multi_index sizes(1);
+ sizes[0] = size;
+ add_fixed_size_data(name, sizes, niter);
}
void model::add_fixed_size_data(const std::string &name,
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();
@@ -770,31 +766,28 @@ namespace getfem {
gmm::copy(t.as_vector(), this->set_complex_variable(name));
}
- void model::add_im_variable(const std::string &name,
- const im_data &im_data,
+ void model::add_im_variable(const std::string &name, const im_data &imd,
size_type niter) {
check_name_validity(name);
- variables[name] = var_description(true, is_complex(), false, niter);
- variables[name].pim_data = &im_data;
+ variables.emplace(name, var_description(true, is_complex(), 0, &imd,
niter));
variables[name].set_size();
- add_dependency(im_data);
+ add_dependency(imd);
act_size_to_be_done = true;
}
- 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].pim_data = &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;
@@ -805,8 +798,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);
@@ -819,7 +812,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;
@@ -829,8 +822,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();
@@ -840,8 +833,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();
@@ -852,9 +845,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);
@@ -864,21 +857,21 @@ 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);
@@ -948,7 +941,7 @@ namespace getfem {
it2 != variables.end(); ++it2) {
if (it2->second.is_fem_dofs &&
(it2->second.filter & VDESCRFILTER_INFSUP) &&
- mim == it2->second.mim) found = true;
+ mim == it2->second.filter_mim) found = true;
}
if (!found) sup_dependency(*mim);
}
@@ -986,7 +979,7 @@ namespace getfem {
if (!found) sup_dependency(*mf);
if (it->second.filter & VDESCRFILTER_INFSUP) {
- const mesh_im *mim = it->second.mim;
+ const mesh_im *mim = it->second.filter_mim;
found = false;
for (dal::bv_visitor ibb(valid_bricks); !ibb.finished(); ++ibb) {
for (size_type j = 0; j < bricks[ibb].mims.size(); ++j)
@@ -996,13 +989,13 @@ namespace getfem {
it2 != variables.end(); ++it2) {
if (it != it2 && it2->second.is_fem_dofs &&
(it2->second.filter & VDESCRFILTER_INFSUP) &&
- mim == it2->second.mim) found = true;
+ mim == it2->second.filter_mim) found = true;
}
if (!found) sup_dependency(*mim);
}
}
- if (it->second.pim_data != 0) sup_dependency(*(it->second.pim_data));
+ if (it->second.imd != 0) sup_dependency(*(it->second.imd));
variables.erase(varname);
act_size_to_be_done = true;
@@ -2691,7 +2684,7 @@ namespace getfem {
model::qdims_of_variable(const std::string &name) const {
auto it = find_variable(no_old_prefix_name(name));
const mesh_fem *mf = it->second.passociated_mf();
- const im_data *imd = it->second.pim_data;
+ const im_data *imd = it->second.imd;
size_type n = it->second.qdim();
if (mf) {
bgeot::multi_index mi = mf->get_qdims();
@@ -2721,7 +2714,7 @@ namespace getfem {
size_type model::qdim_of_variable(const std::string &name) const {
auto it = find_variable(no_old_prefix_name(name));
const mesh_fem *mf = it->second.passociated_mf();
- const im_data *imd = it->second.pim_data;
+ const im_data *imd = it->second.imd;
size_type n = it->second.qdim();
if (mf) {
return mf->get_qdim() * n;