[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] r5034 - in /trunk/getfem: interface/src/gf_model_set.cc
From: |
logari81 |
Subject: |
[Getfem-commits] r5034 - in /trunk/getfem: interface/src/gf_model_set.cc src/getfem/getfem_models.h src/getfem_models.cc |
Date: |
Thu, 11 Jun 2015 12:06:37 -0000 |
Author: logari81
Date: Thu Jun 11 14:06:35 2015
New Revision: 5034
URL: http://svn.gna.org/viewcvs/getfem?rev=5034&view=rev
Log:
accept a dataname as the rhs in bricks with private data
Modified:
trunk/getfem/interface/src/gf_model_set.cc
trunk/getfem/src/getfem/getfem_models.h
trunk/getfem/src/getfem_models.cc
Modified: trunk/getfem/interface/src/gf_model_set.cc
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/interface/src/gf_model_set.cc?rev=5034&r1=5033&r2=5034&view=diff
==============================================================================
--- trunk/getfem/interface/src/gf_model_set.cc (original)
+++ trunk/getfem/interface/src/gf_model_set.cc Thu Jun 11 14:06:35 2015
@@ -1316,13 +1316,15 @@
out.pop().from_integer(int(ind));
);
- /address@hidden ind = ('add constraint with multipliers', @str varname,
@str multname, @tspmat B, @vec L)
+ /address@hidden ind = ('add constraint with multipliers', @str varname,
@str multname, @tspmat B, address@hidden L | @str dataname})
Add an additional explicit constraint on the variable `varname` thank to
a multiplier `multname` peviously added to the model (should be a fixed
size variable). The constraint is :math:`BU=L`
with `B` being a rectangular sparse matrix. It is possible to change
the constraint at any time with the methods MODEL:SET('set private matrix')
- and MODEL:SET('set private rhs'). Return the brick index in the
address@hidden/
+ and MODEL:SET('set private rhs'). If `dataname` is specified instead of
`L`,
+ the vector `L` is defined in the model as data with the given name.
+ Return the brick index in the address@hidden/
sub_command
("add constraint with multipliers", 4, 4, 0, 1,
std::string varname = in.pop().to_string();
@@ -1352,7 +1354,10 @@
THROW_BADARG("Constraint matrix should be a sparse matrix");
}
- if (!md->is_complex()) {
+ if (in.front().is_string()) {
+ std::string dataname = in.pop().to_string();
+ getfem::set_private_data_rhs(md->model(), ind, dataname);
+ } else if (!md->is_complex()) {
darray st = in.pop().to_darray();
std::vector<double> V(st.begin(), st.end());
getfem::set_private_data_rhs(md->model(), ind, V);
@@ -1366,14 +1371,17 @@
);
- /address@hidden ind = ('add constraint with penalization', @str varname,
@scalar coeff, @tspmat B, @vec L)
+ /address@hidden ind = ('add constraint with penalization', @str varname,
@scalar coeff, @tspmat B, address@hidden L | @str dataname})
Add an additional explicit penalized constraint on the variable `varname`.
The constraint is :math`BU=L` with `B` being a rectangular sparse matrix.
Be aware that `B` should not contain a palin row, otherwise the whole
tangent matrix will be plain. It is possible to change the constraint
at any time with the methods MODEL:SET('set private matrix')
and MODEL:SET('set private rhs'). The method
- MODEL:SET('change penalization coeff') can be used. Return the brick
+ MODEL:SET('change penalization coeff') can be used.
+ If `dataname` is specified instead of `L`, the vector `L` is defined
+ in the model as data with the given name.
+ Return the brick
index in the address@hidden/
sub_command
("add constraint with penalization", 4, 4, 0, 1,
@@ -1404,7 +1412,10 @@
THROW_BADARG("Constraint matrix should be a sparse matrix");
}
- if (!md->is_complex()) {
+ if (in.front().is_string()) {
+ std::string dataname = in.pop().to_string();
+ getfem::set_private_data_rhs(md->model(), ind, dataname);
+ } else if (!md->is_complex()) {
darray st = in.pop().to_darray();
std::vector<double> V(st.begin(), st.end());
getfem::set_private_data_rhs(md->model(), ind, V);
@@ -1474,14 +1485,19 @@
the right hand side of the tangent linear system relatively to the
variable `varname`. The given rhs should have the same size than the
dimension of `varname`. The rhs can be changed by the command
- MODEL:SET('set private rhs'). Return the brick index in the
address@hidden/
+ MODEL:SET('set private rhs'). If `dataname` is specified instead of
+ `L`, the vector `L` is defined in the model as data with the given name.
+ Return the brick index in the address@hidden/
sub_command
("add explicit rhs", 2, 2, 0, 1,
std::string varname = in.pop().to_string();
size_type ind
= getfem::add_explicit_rhs(md->model(), varname);
- if (!md->is_complex()) {
+ if (in.front().is_string()) {
+ std::string dataname = in.pop().to_string();
+ getfem::set_private_data_rhs(md->model(), ind, dataname);
+ } else if (!md->is_complex()) {
darray st = in.pop().to_darray();
std::vector<double> V(st.begin(), st.end());
getfem::set_private_data_rhs(md->model(), ind, V);
Modified: trunk/getfem/src/getfem/getfem_models.h
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/getfem_models.h?rev=5034&r1=5033&r2=5034&view=diff
==============================================================================
--- trunk/getfem/src/getfem/getfem_models.h (original)
+++ trunk/getfem/src/getfem/getfem_models.h Thu Jun 11 14:06:35 2015
@@ -257,7 +257,7 @@
}
size_type size(void) const // Should control that the variable is
- // indeed intitialized by actualize_sizes ...
+ // indeed initialized by actualize_sizes() ...
{ return is_complex ? complex_value[0].size() : real_value[0].size(); }
void set_size(void);
@@ -2272,6 +2272,9 @@
size_type APIDECL add_constraint_with_multipliers
(model &md, const std::string &varname, const std::string &multname);
+ void set_private_data_rhs
+ (model &md, size_type indbrick, const std::string &varname);
+
template <typename VECT, typename T>
void set_private_data_rhs(model &md, size_type ind,
const VECT &L, T) {
Modified: trunk/getfem/src/getfem_models.cc
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem_models.cc?rev=5034&r1=5033&r2=5034&view=diff
==============================================================================
--- trunk/getfem/src/getfem_models.cc (original)
+++ trunk/getfem/src/getfem_models.cc Thu Jun 11 14:06:35 2015
@@ -5634,19 +5634,19 @@
model_complex_sparse_matrix cB;
model_real_plain_vector rL;
model_complex_plain_vector cL;
-
+ std::string nameL;
};
struct constraint_brick : public have_private_data_brick {
virtual void real_pre_assembly_in_serial(const model &md, size_type,
- const model::varnamelist &vl,
- const model::varnamelist &dl,
- const model::mimlist &mims,
- model::real_matlist &matl,
- model::real_veclist &vecl,
- model::real_veclist &,
- size_type, build_version) const {
+ const model::varnamelist &vl,
+ const model::varnamelist &dl,
+ const model::mimlist &mims,
+ model::real_matlist &matl,
+ model::real_veclist &vecl,
+ model::real_veclist &,
+ size_type, build_version) const {
if (MPI_IS_MASTER()) {
GMM_ASSERT1(vecl.size() == 1 && matl.size() == 1,
@@ -5659,31 +5659,39 @@
bool penalized = (vl.size() == 1);
const model_real_plain_vector *COEFF = 0;
+ bool has_data = (nameL.compare("") != 0);
+ if (has_data)
+ GMM_ASSERT1(nameL.compare(dl.back()) == 0 &&
+ md.variable_exists(nameL) && md.is_data(nameL),
+ "Internal error");
+ const model_real_plain_vector &
+ rrL = has_data ? md.real_variable(nameL) : rL;
+
if (penalized) {
COEFF = &(md.real_variable(dl[0]));
GMM_ASSERT1(gmm::vect_size(*COEFF) == 1,
"Data for coefficient should be a scalar");
gmm::mult(gmm::transposed(rB),
- gmm::scaled(rL, gmm::abs((*COEFF)[0])), vecl[0]);
+ gmm::scaled(rrL, gmm::abs((*COEFF)[0])), vecl[0]);
gmm::mult(gmm::transposed(rB),
gmm::scaled(rB, gmm::abs((*COEFF)[0])), matl[0]);
} else {
- gmm::copy(rL, vecl[0]);
+ gmm::copy(rrL, vecl[0]);
gmm::copy(rB, matl[0]);
}
}
}
virtual void complex_pre_assembly_in_serial(const model &md, size_type,
- const model::varnamelist &vl,
- const model::varnamelist &dl,
- const model::mimlist &mims,
- model::complex_matlist &matl,
- model::complex_veclist &vecl,
- model::complex_veclist &,
- size_type,
- build_version) const {
+ const model::varnamelist &vl,
+ const model::varnamelist &dl,
+ const model::mimlist &mims,
+ model::complex_matlist &matl,
+ model::complex_veclist &vecl,
+ model::complex_veclist &,
+ size_type,
+ build_version) const {
if (MPI_IS_MASTER()) {
GMM_ASSERT1(vecl.size() == 1 && matl.size() == 1,
@@ -5696,17 +5704,25 @@
bool penalized = (vl.size() == 1);
const model_complex_plain_vector *COEFF = 0;
+ bool has_data = (nameL.compare("") != 0);
+ if (has_data)
+ GMM_ASSERT1(nameL.compare(dl.back()) == 0 &&
+ md.variable_exists(nameL) && md.is_data(nameL),
+ "Internal error");
+ const model_complex_plain_vector &
+ ccL = has_data ? md.complex_variable(nameL) : cL;
+
if (penalized) {
COEFF = &(md.complex_variable(dl[0]));
GMM_ASSERT1(gmm::vect_size(*COEFF) == 1,
"Data for coefficient should be a scalar");
gmm::mult(gmm::transposed(cB),
- gmm::scaled(cL, gmm::abs((*COEFF)[0])), vecl[0]);
+ gmm::scaled(ccL, gmm::abs((*COEFF)[0])), vecl[0]);
gmm::mult(gmm::transposed(cB),
gmm::scaled(cB, gmm::abs((*COEFF)[0])), matl[0]);
} else {
- gmm::copy(cL, vecl[0]);
+ gmm::copy(ccL, vecl[0]);
gmm::copy(cB, matl[0]);
}
}
@@ -5746,6 +5762,7 @@
have_private_data_brick *p = dynamic_cast<have_private_data_brick *>
(const_cast<virtual_brick *>(pbr.get()));
GMM_ASSERT1(p, "Wrong type of brick");
+ if (p->nameL.compare("") != 0) GMM_WARNING1("Rhs already set by data
name");
return p->rL;
}
@@ -5766,7 +5783,24 @@
have_private_data_brick *p = dynamic_cast<have_private_data_brick *>
(const_cast<virtual_brick *>(pbr.get()));
GMM_ASSERT1(p, "Wrong type of brick");
+ if (p->nameL.compare("") != 0) GMM_WARNING1("Rhs already set by data
name");
return p->cL;
+ }
+
+ void set_private_data_rhs
+ (model &md, size_type indbrick, const std::string &varname) {
+ pbrick pbr = md.brick_pointer(indbrick);
+ md.touch_brick(indbrick);
+ have_private_data_brick *p = dynamic_cast<have_private_data_brick *>
+ (const_cast<virtual_brick *>(pbr.get()));
+ GMM_ASSERT1(p, "Wrong type of brick");
+ if (p->nameL.compare(varname) != 0) {
+ model::varnamelist dl = md.datanamelist_of_brick(indbrick);
+ if (p->nameL.compare("") == 0) dl.push_back(varname);
+ else dl.back() = varname;
+ md.change_data_of_brick(indbrick, dl);
+ p->nameL = varname;
+ }
}
size_type add_constraint_with_penalization
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Getfem-commits] r5034 - in /trunk/getfem: interface/src/gf_model_set.cc src/getfem/getfem_models.h src/getfem_models.cc,
logari81 <=