CustomUExtFunction within CustomExactFunction*

18 views
Skip to first unread message

Tomas Svaton

unread,
Nov 8, 2013, 6:43:40 AM11/8/13
to herm...@googlegroups.com
Hello everybody,

I have taken a look on the class UExtFunction. Could someone suggest me how to implement the following issue:

class CustomUExtFunction : public UExtFunction<double>
{
public:
  CustomUExtFunction(double mu, double lambda, CustomExactFunction* MyFun) : UExtFunction<double>(), mu(mu), lambda(lambda), MyFun(MyFun)
  {
  }
  virtual void value (int n, Func<double>** u_ext, Func<double>* result, Geom<double>* geometry) const
  {
    for(int i = 0; i < n; i++)
    {
      double ux = u_ext[0]->dx[i];
      double uy = u_ext[0]->dy[i];
      double vx = u_ext[1]->dx[i];
      double vy = u_ext[1]->dy[i];
      double dS11dE11 = mu * MyFun * ux;
      result->val[i] = dS11dE11;
    }
  };

  virtual void ord(Func<Hermes::Ord>** u_ext, Func<Hermes::Ord>* result) const
  {
    result->val[0] = u_ext[mu]->val[0];
  };

  int mu;
  CustomExactFunction* MyFun;
};

The problem is in the incompatibility of the datatypes on the line:
double dS11dE11 = -2.0/3.0 * mu * MyFun * ux;

This would permit to implement more complex weak forms with non constant coefficients over the domain.

Thanks for any help or advice.

Kind regards,
Tomas.

Lukas Korous

unread,
Nov 8, 2013, 8:19:13 AM11/8/13
to herm...@googlegroups.com
Hello Tomas,

could you send description of the class CustomExactFunction?

Thanks,
Lukas
> --
> You received this message because you are subscribed to the Google Groups
> "hermes2d" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hermes2d+u...@googlegroups.com.
> To post to this group, send email to herm...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hermes2d.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Lukáš Korous

Tomas Svaton

unread,
Nov 8, 2013, 8:29:05 AM11/8/13
to herm...@googlegroups.com
Hello Lukas,

I am sorry about my rough question. This is the custom function in definitions.cpp

double CustomExactFunction::val(double x, double y)
{
  double scaleNu = 10;
  double scaleE = 10;
  double Eln = E * (1-1.0/scaleE) * y + E/scaleE;
  double nuln = nu * (1.0-1.0/scaleNu) * y + nu/scaleNu;
  return (Eln * nuln) / ((1 + nuln) * (1 - 2*nuln));
}
double CustomExactFunction::dx(double x, double y)
{
  return 0.0;
}
double CustomExactFunction::ddxx(double x, double y)
{
  return 0.0;
}

and its declaration definititon.h

class CustomExactFunction
{
public:
  CustomExactFunction(double E, double nu) : E(E), nu(nu) {};
  double val(double x, double y);
  double dx(double x, double y);
  double ddxx(double x, double y);
protected:
  double E, nu;
};

Thank you very much once more.

Kind regards,
Tomas.

Lukas Korous

unread,
Nov 8, 2013, 10:38:49 AM11/8/13
to herm...@googlegroups.com
OK then,

you can probably just write:


...

double dS11dE11 = mu * MyFun->val(geometry->x[i], geometry->y[i]) * ux;

...

Am I right?

Lukas

Tomas Svaton

unread,
Nov 8, 2013, 11:03:06 AM11/8/13
to herm...@googlegroups.com
Thank you very much, Lukas. 

You are true ant it works.

Kind regards,
Tomas.

Lukas Korous

unread,
Nov 8, 2013, 11:21:11 AM11/8/13
to herm...@googlegroups.com
Cool,

send some pictures-results, I would be interested :-).

Regards,
Lukas

Tomas Svaton

unread,
Nov 10, 2013, 9:34:27 PM11/10/13
to herm...@googlegroups.com
Hi Lukas,

I thought I understood the way, but there is still something missing to me in the implementation and I have still ask you. Could you take a look on it, please?

I have this code in main.cpp (like is in devel):
...
UExtFunctionSharedPtr<double> fn_0(new CustomUExtFunction(0));
DiscreteProblem<double> dp(&wf, spaces);
wf.set_u_ext_fn(fn_0);
...

My question is: How could I access the variable fn_0 via definitions.cpp (eventually via definitions.h) and use it in the definitions of custom weak forms, e.g. in cycles like

double result = 0;
for (int i = 0; i < n; i++)
{
  result += - wt[i] * (mu * fn_0->val[i] * u->dx[i] * v->dx[i]);  // here function fn_0=sqrt(u_1 + u_2)
}
return result;

I did not found it in devel. I use the scheme (maybe obsolete now) "definitions.cpp & definitions.h & main.cpp" and I have touched the original class which is in devel inthe following way (to be splitted into definitions.cpp and definitions.h):

I have created an example of function in definitions.cpp

CustomUExtFunction::CustomUExtFunction(int index) : UExtFunction<double>(), index(index) {}
void CustomUExtFunction::value(int n, Func<double>** u_ext, Func<double>* result, Geom<double>* geometry) const
{
  for(int i = 0; i < n; i++)
  {
    result->val[i] = Hermes::pow(u_ext[0]->val[i] + u_ext[1]->val[i],1.0/2.0);
    result->dx[i] = u_ext[index]->dx[i];
    result->dy[i] = u_ext[index]->dy[i];
  }
}
void CustomUExtFunction::ord(Func<Hermes::Ord>** u_ext, Func<Hermes::Ord>* result) const
{
  result->val[0] = u_ext[index]->val[0];
};

then the interface in definitions.h

class CustomUExtFunction : public UExtFunction<double>
{
public:
  CustomUExtFunction(int index);
  virtual void value(int n, Func<double>** u_ext, Func<double>* result, Geom<double>* geometry) const;
  virtual void ord(Func<Hermes::Ord>** u_ext, Func<Hermes::Ord>* result) const;
protected :
  int index;
};

Anyway I enclose the most recent obtained results with Hermes. I hope you will enjoy them.

I will be glad for any advice.

Thank you in advance.

Kind regards,
Tomas.
displacement_u.png
hydrostatic_pressure.png
vonMises.png
vonMisesTop.png

Tomas Svaton

unread,
Nov 11, 2013, 9:30:32 AM11/11/13
to hermes2d
Hi Lukas,

Stop, stop, stop, please. I am sorry about a little bit chaos. I am trying now another way that I did not realised is much more simple.

I will keep you informed.

Anyway thank you very much.

Kind regards,
Tomas.


You received this message because you are subscribed to a topic in the Google Groups "hermes2d" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hermes2d/W9j8CoZ1tyw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hermes2d+u...@googlegroups.com.

Lukas Korous

unread,
Nov 11, 2013, 7:09:16 PM11/11/13
to herm...@googlegroups.com
Hi,

sorry for delay, it's a rather busy time now.

Hi,

basically, the behavior - not documented yet - sorry, is that whatever
you put to the "u_ext functions" through

wf.set_u_ext_fn(fn_0);

appears in the front of the ext array in the value method, so you would write:

for (int i = 0; i < n; i++)
{
result += - wt[i] * (mu * ext[0]->val[i] * u->dx[i] * v->dx[i]);
}

And your scheme is just fine, it is not obsolete at all.
Nice pictures.
Lukas
Reply all
Reply to author
Forward
0 new messages