initializing values using random numbers (of doubles in an interval)

54 views
Skip to first unread message

Karthi

unread,
Jan 6, 2021, 11:13:00 AM1/6/21
to deal.II User Group

Dear All,

I'm new to dealii and worked through the tutorials. I am currently trying to an implement a 6th order parabolic equation by breaking it into three second order equations.

Thus I have a FeSystem (and tried to mimic tutorial step-21) with dim = 2 using

fe(FE_Q<dim>(degree), 1,FE_Q<dim>(degree),1,FE_Q<dim>(degree),1)

I used random initializing to initialize one of the variables

 class InitialValues : public Function<dim>{

public: InitialValues()  : Function<dim>(dim + 1){}

    virtual void vector_value(const Point<dim> & /*p*/,Vector<double> &  values) const override{

      Assert(values.size() == dim + 1,ExcDimensionMismatch(values.size(), dim + 1));

      values(0) = 0.0; // inital condition for mu                                                                               

      double fMin = -0.1;

      double fMax =  0.5;

      double f = (double)rand() /  (double)RAND_MAX;

      values(1) =  fMin + f * (fMax - fMin); // initial condition for psi                                                      

      values(2) = 0.0; // initial condition for omega }};

Then in run()

Question (1) Should I use VectorTools::project or VectorTools::interpolate for initializing the variables?

VectorTools::project(dof_handler,constraints,QGauss<dim>(degree + 1),InitialValues<dim>(),old_solution);

VectorTools::interpolate(dof_handler,InitialValues<dim>(),old_solution);

Both the initial conditions are not giving the desired steady state solution (possibly there is a bug that is not related with the initial condition). However, I want to make sure I understand how to set up initial condition generated using random values.

Question (2)Though, I set the initial condition only to one of the three solution variables, in the output I see all three variables initialized (with values different from zero) at time zero. I copied ‘output’ from tutorial step-21. Maybe the output is not generated at time zero or I made a mistake in the set up InitialValues?

Question (3)Since, I have a system of three variables (each with FE_Q<dim>(1) finite element space) in my function InitialValues I only defined InitialValues::vector_value and not InitialValues::value. Did I do right?

Thank you and I look forward to your response.

Best regards,

Karthi.

Wolfgang Bangerth

unread,
Jan 7, 2021, 11:48:01 PM1/7/21
to dea...@googlegroups.com, Karthi
On 1/6/21 9:12 AM, Karthi wrote:
>
> Question (1) Should I use VectorTools::project or VectorTools::interpolate for
> initializing the variables?
In practice, it does not matter very much, but interpolate() is much cheaper
than project().


> Both the initial conditions are not giving the desired steady state solution
> (possibly there is a bug that is not related with the initial condition).
> However, I want to make sure I understand how to set up initial condition
> generated using random values.

Have you tried to figure out *how specifically* it is wrong?


> Question (2)Though, I set the initial condition only to one of the three
> solution variables, in the output I see all three variables initialized (with
> values different from zero) at time zero. I copied ‘output’ from tutorial
> step-21. Maybe the output is not generated at time zero or I made a mistake in
> the set up InitialValues?

I don't have access to your code, so I can't tell. The implementation of your
vector_value() function looks correct to me. If you don't know which time step
the function is called, then it's probably worth just running a single time
step and looking at the output after that step.


> Question (3)Since, I have a system of three variables (each with FE_Q<dim>(1)
> finite element space) in my function InitialValues I only defined
> InitialValues::vector_value and not InitialValues::value. Did I do right?

I think so. You would have gotten an error message (assuming you are working
in debug mode) if you had done that wrong.

Best
W.


--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Karthi

unread,
Jan 8, 2021, 5:56:25 AM1/8/21
to deal.II User Group
Dear Wolfgang,

Thank you for your response. I am working on phase-stability in materials, for smooth initial conditions it produces the correct phase but for random initialization it produces a phase which I am not expecting. The phases are every sensitive to the initial-conditions used.  If I happen to figure out the issue, I will post back my findings.

Cheers,
Karthi.

Reply all
Reply to author
Forward
0 new messages