[dune-fem] [Dune] Store Data in grid cells

Andreas Dedner a.s.dedner at warwick.ac.uk
Sat Apr 2 15:46:16 CEST 2016


Hi Justus.
You are mixing concepts a bit. The fv example in the howto shows how
piecewise constant data can be attached to cells quite easily using
dune-fem concepts. If I see things correctly you took the elementdata
from the dune-grid-howto and called the method from within main(...).
That method sets up the mapper class and outputs the results to a vtk
file. This results is not used anywhere afterwards? What you are seeing,
is that the vtk file does not contain a constant value (the code you
send has a 6 there in your email you wrote 2) on each cell as you
expected but only the "standard values"? What does that mean exactly?
Have you checked what c[0],c[1] etc. contain after the loop over the grid?

That said: I would not advice to mix the dune-fem features with the
dune-grid-howto code. Most things can be done easier and more natural
using dune-fem classes and it will then fit much more easily with other
dune-fem code. Perhaps a short explanation what you want to achieve
would be helpful. Are you trying to build a time dependent finite-volume
method? Then starting either from the fv example or the heat example
might be a good idea. There are different ways of initializing discrete
functions within dune-fem that you can use and which are explained in
the dune-fem-howto examples.

As you can see I moved this discussion onto the dune-fem mailing list
because I think that is the better place for it. So just "reply to all".

Best
Andreas


On 30/03/16 21:07, Schock, Justus wrote:
> Hi,
> 
> 
> No I am not. I tried to combine the poisson-dg from the dune-fem-howto
> (with changed problemcases) and the elementdata.hh from the dune-grid-howto:
> 
> Therefor I wanted to set grid-element-data before starting the
> refinement end EOC-Loop in the main.cc of the poisson-dg:
> 
> 
>                   // refine grid and set elementvalues
>         Dune::Fem::GlobalRefine::apply( grid, level * refineSteps );
>         initialvalues<typename GridType::ctype, GridType::dimension>
> initial;
>         elementdata(grid, initial);
> 
>         // setup EOC loop
> 
>         // calculate first step
>         double oldError = algorithm( grid, (repeats > 0) ? 0 : -1,
> problemNumber );
> 
>         for( int step = 1; step <= repeats; ++step )
>         {
>             // refine globally such that grid with is bisected
>             // and all memory is adjusted correctly
>             Dune::Fem::GlobalRefine::apply( grid, refineSteps );
> 
> 
> 
>             const double newError = algorithm( grid, step, problemNumber );
>             const double eoc = log( oldError / newError ) / M_LN2;
>             if( Dune::Fem::MPIManager::rank() == 0 )
>             {
>                 std::cout << "Error step " << step << " :" << newError
> << std::endl;
>                 std::cout << "EOC( " << step <<"/"<< step-1 <<" ) = " <<
> eoc << std::endl;
>             }
>             oldError = newError;
>         }
> 
> 
> with the following class to get a constant value for every cell:
> 
>         template<typename ct, int dim>
> 
>         class initialvalues {
> 
> 
>         protected:
> 
>             virtual double f(const Dune::FieldVector<ct,dim> &x) const{
> 
>                 return 6;
> 
>             }
> 
> 
>         public:
> 
>             initialvalues () { }
> 
> 
>             double operator() (const Dune::FieldVector<ct,dim>& x) const
> 
>             {
> 
>                 return f(x);
> 
>             }
> 
> 
>         };​
> 
> 
> 
> I attatched the elementdata.hh and the changed main.cc I used.
> 
> 
> I don't know, whether I tried to use the wrong concept in this case,
> wanted to do it at the wrong time or had a failure in implementation
> and would be very grateful for any hints or proposals.
> 
> 
> Best
> 
> Justus
> 
> ------------------------------------------------------------------------
> *Von:* Dedner, Andreas <A.S.Dedner at warwick.ac.uk>
> *Gesendet:* Dienstag, 29. März 2016 09:06
> *An:* Schock, Justus
> *Betreff:* Re: [Dune] Store Data in grid cells
>  
> Hi.
> Are you working with the fv example from the dune-fem-howto?
> Could you please send a code snippet showing what you are trying to do?
> Best 
> Andreas 
> 
> 
> 
> Sent from my Samsung device
> 
> 
> -------- Original message --------
> From: "Schock, Justus" <justus.schock at rwth-aachen.de>
> Date: 29/03/2016 07:29 (GMT+01:00)
> To: Oliver Sander <oliver.sander at tu-dresden.de>
> Cc: dune <dune at dune-project.org>
> Subject: Re: [Dune] Store Data in grid cells
> 
> Hi Oliver,
> 
> "it doesn't work" in this case means, the expected data isn't stored in
> the cells.
> 
> I wrote a class, which constantly returns the value 2 and expected,
> giving this class to the elementdata function, the value 2 to appear in
> every cell. If I plot the grid (via vtk) there are no 2s in the cells,
> only the standard values.
> 
> I didn't try the poisson solver attached to the how-to yet because I
> want to work with dune-fem and my code works for the standard values
> except that I cannot set my own initial values, which I assume to be a
> general problem.
> 
> Best
> Justus
> 
> -------- Originalnachricht --------
> Betreff: Re: [Dune] Store Data in grid cells
> Von: Oliver Sander
> An: "Schock, Justus" ,DUNE Liste
> Cc:
> 
> Hi Justus,
> 
> your question is a little vague.  What exactly do you mean by "did not work
> as expected"?
> 
> The grid how-to also contains a complete implementation of a finite
> element solver
> for the Poisson equation (in Chapter 6.4).  Did you try that?  Do you
> have problems
> with that one, too?
> 
> Best,
> Oliver
> 
> On 25.03.2016 01:50, Schock, Justus wrote:
>> Dear Duners,
>> 
>> 
>> I want to use DUNE for solving PDEs (just like the Poisson-Equation or the Diffusion-Equation).
>> 
>> 
>> This is why I want to store some data (like concentration etc.) directly in the cells of the grid.
>> 
>> 
>> I even tried using Mappers (as explained in chapter 6 of the How-To) and tried to write something very similar to the elementdata.hh.
>> 
>> ​Unfortunately it did not work as expected and I dont't know if it has been the wrong idea in general or only a wrong implementation.
>> 
>> 
>> Furthermore I texperimented a bit with the DGF, trying to pass the cell data directly in the file, the grid is constructed from.
>> 
>> 
>> Could anyone just give me a hint or some explanation/link/example how this should be done?
>> 
>> 
>> Best,
>> Justus
>> 
>> 
>> 
>> _______________________________________________
>> Dune mailing list
>> Dune at dune-project.org
>> http://lists.dune-project.org/mailman/listinfo/dune
>> 
> 




More information about the dune-fem mailing list