[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-users] nonlinear brick

From: Roman Putanowicz
Subject: [Getfem-users] nonlinear brick
Date: Wed, 24 Mar 2010 16:15:35 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Dear All, 

Could someone, please, point me to an example involving nonlinear brick
using the new brick system?

Actually, I am trying to get the real filling of GetFEM++ internals.
I just thought to use GetFEM++ to solve a problem which boils down 
to a single quadratic scalar equation. I know that this is not what
GetFEM++ was meant for, but in principle GetFEM++ allows to model board
kind of mathematical models so why not this :).

I have defined the following brick:

namespace getfem {
  struct my_quadratic_eq_brick : public virtual_brick {
    void asm_real_tangent_terms(const model &md, 
                              getfem::size_type ib,
                              const model::varnamelist &varl,
                              const model::varnamelist &datal,
                              const model::mimlist &mims,
                              model::real_matlist &matl,
                              model::real_veclist &vecl,
                              model::real_veclist &vecl_sym,
                              size_type region, 
                              model::build_version nl) const {

      GMM_ASSERT1(matl.size() == 1, "my_quadratic_eq_brick has only one term");
      GMM_ASSERT1(mims.size() == 0, 
        "my_quadratic_eq_brick does not need mesh_im");
      GMM_ASSERT1(varl.size() == 1 && datal.size() == 1, 
        "Wrong number of varibles for my_quadratic_eq_brick");

      /* get equation coefficients */
      const model_real_plain_vector COEFF = md.real_variable(datal[0]);
      gmm::dense_matrix<double> mm(1,1);
      double a = vecl[0][0];
      mm(0,0) = COEFF[0]*a*2.0 + COEFF[1];
      gmm::copy(mm, matl[0]);

    my_quadratic_term_brick(bool symmetric_, bool coercive_) {
      set_flags("Quadratic term brick",
                  false /* is linear*/,
                  symmetric_ /* is symmetric */, coercive_ /* is coercive */,
                  true /* is real */, true /* is complex */);

  size_type add_my_quadratic_eq_brick
  (model &md, const std::string &varname, const std::string &dataname) {
    pbrick pbr = new my_quadratic_term_brick(false, false);
    model::termlist tl;
    tl.push_back(model::term_description(varname, varname, true));
    model::varnamelist dl;
    return md.add_brick(pbr, model::varnamelist(1, varname), dl, tl,
                        model::mimlist(), size_type(-1));
} /* namespace getfem */

Well, so far so good.

Now a bit of code which uses the brick:

  md.add_fixed_size_variable("x", 1);
  std::vector<scalar_type> F(1);
  std::vector<scalar_type> coeff(3);
  coeff[0] = 7.0;
  coeff[1] = 11.0;
  coeff[2] = 2.0;
  md.add_initialized_fixed_size_data("coeff", coeff);


  F[0] = 2.0;
  gmm::copy(F, md.set_real_variable("x"));

  getfem::size_type id = add_my_quadratic_eq_brick(md, "x", "coeff");

  std::cout << md.real_tangent_matrix();

And here is the problem. On standard output I get the 1 by 1 matrix
whose only element value is 11 (the coefficient at linear term in the 
equation). So it seems that the "x" vector is uninitialised.
Is there any mechanism that ensures that the tangent matrix
will be built on the basis of supplied guessed solution?

I thought that this will be done with these two lines

F[0] = 2.0;
gmm::copy(F, md.set_real_variable("x"));

but apparently I miss something. 

I would appreciate any hint.


Roman Putanowicz, PhD  < address@hidden  >
Institute for Computational Civil Engng (L-5)
Dept. of Civil Engng, Cracow Univ. of Technology, tel. +48 12 628 2569, fax 2034

reply via email to

[Prev in Thread] Current Thread [Next in Thread]