using .vtk file as initial condition

133 views
Skip to first unread message

Anup Basak

unread,
Oct 11, 2016, 6:59:49 PM10/11/16
to deal.II User Group
Dear all,

I have a solution saved in two .vtk files for a mechanics problem (displacement, stress, strain, temperature etc.
at the nodal points). Now let us say I want to use this as initial conditions for another problem (the domain,
boundary conditions, and meshes are identical for both the problems). Could anyone please suggest that
how should I implement it.

Thanks,
Anup.

Jean-Paul Pelteret

unread,
Oct 12, 2016, 2:29:01 AM10/12/16
to deal.II User Group
Dear Anup.

I notice that this question has been asked before, but remains without an answer. I'm not sure that this is possible - so far, save and load functions only read/write to boost archive data structures. You're probably better off investigating using these functions instead of a VTK file. That being said, if its an ASCII VTK file then it wouldn't be too difficult it wouldn't be too difficult to implement such functionality. But things could get tricky if you are using parallel data structures. 

Regards,
J-P

Timo Heister

unread,
Oct 14, 2016, 2:52:00 PM10/14/16
to dea...@googlegroups.com
.vtk files are visualization output, which always involves some loss
of information (for example we interpolate linearly to the vertices of
each cell by default), so therefore it is
complicated/inaccurate/undesirable to reconstruct a finite element
solution vector from it. This is the reason nobody has implemented
this inside deal.II so far. You should consider storing the finite
element solution and read that back in or do what J-P suggests.
> --
> The deal.II project is located at https://urldefense.proofpoint.com/v2/url?u=http-3A__www.dealii.org_&d=CwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=4k7iKXbjGC8LfYxVJJXiaYVu6FRWmEjX38S7JmlS9Vw&m=ItwOC0neOpqcosvpqST2azKxUqBCeihSaE71KljSX5k&s=utGxqw4FA4GTJrqTHK-pMzDeWHX906ycL5y2BTDm5VU&e=
> For mailing list/forum options, see
> https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_forum_dealii-3Fhl-3Den&d=CwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=4k7iKXbjGC8LfYxVJJXiaYVu6FRWmEjX38S7JmlS9Vw&m=ItwOC0neOpqcosvpqST2azKxUqBCeihSaE71KljSX5k&s=NvnyBWAmMqXf1ji8zz6NQ9zrD-5tM-0RXGWHuI48rWQ&e=
> ---
> You received this message because you are subscribed to the Google Groups
> "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dealii+un...@googlegroups.com.
> For more options, visit https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_optout&d=CwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=4k7iKXbjGC8LfYxVJJXiaYVu6FRWmEjX38S7JmlS9Vw&m=ItwOC0neOpqcosvpqST2azKxUqBCeihSaE71KljSX5k&s=Cdt_SsJ9xS_vt6t8lyvpIFqOUHyn-imvC7IVOeNoZJs&e= .



--
Timo Heister
http://www.math.clemson.edu/~heister/

Anup Basak

unread,
Nov 1, 2016, 7:23:09 PM11/1/16
to dea...@googlegroups.com
Dear Jean-Paul and Timo,

Thank you very much for your reply.

I would like to use 'save ()' and 'load() ' functions as both of you suggested, but it is not
fully clear to me how should they be used in the dealii code (I am using a code similar to step-44
large deformation problem). Suppose I need  to save all the trangulation information and
data like displacements, stresses, strains, etc. and use them as initial data on the saved
 geometry.

It would be very helpful if you kindly explain little elaborately and tell me if any of the examples
has used this idea (or some other reference).

Thanks a lot.

Regards,
Anup.





--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en

---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anup Basak

unread,
Nov 6, 2016, 8:43:01 PM11/6/16
to deal.II User Group
Hello all,

I shall be thankful if someone could tell me in details how to use 'save()' and 'load()' functions to save and load
triangulation information and the nodal values of displacements, strains, stresses, and may be temperature
(similar to step44) so that they can be used as initial data in another simulations with the identical triangulation data.

Or if there is some other simpler way.

Thanks and regards,
Anup.

Jean-Paul Pelteret

unread,
Nov 7, 2016, 1:06:50 AM11/7/16
to deal.II User Group
Dear Anup,

Probably the simplest way to find examples of the save and load functionality is to look through deal.II's unit tests. Here are a list of tests that are related to the save functionality

$ grep --include=\*.{h,cpp,cc} -rnw '.' -e "save"
./arpack/parpack_advection_diffusion_petsc.cc:58:const unsigned int dim = 2;//run in 2d to save time
./arpack/parpack_advection_diffusion_trilinos.cc:57:const unsigned int dim = 2;//run in 2d to save time
./arpack/step-36_parpack.cc:61:const unsigned int dim = 2;//run in 2d to save time
./arpack/step-36_parpack_trilinos.cc:60:const unsigned int dim = 2;//run in 2d to save time
./bits/refine_and_coarsen_for_active_cell_index_05.cc:112:    // save data to archive
./bits/refine_and_coarsen_for_active_cell_index_05.cc:141:    // save data to archive
./distributed_grids/2d_refinement_10.cc:279:  // save refine flag
./distributed_grids/3d_refinement_12.cc:279:  // save refine flag
./grid/user_data_01.cc:184:  // Check if save and load work
./grid/user_data_01.cc:263:  // Check if save and load work
./hp/renumber_block_wise_01.cc:68:  // do component-wise and save the
./hp/renumber_block_wise_01a.cc:67:  // do component-wise and save the
./hp/renumber_block_wise_02.cc:78:  // do component-wise and save the
./lac/la_vector_output.cc:52:  // save data to archive
./mpi/p4est_save_01.cc:18:// save and load a triangulation
./mpi/p4est_save_01.cc:70:    tr.save(filename.c_str());
./mpi/p4est_save_02.cc:18:// save and load a triangulation with one solution vector
./mpi/p4est_save_02.cc:98:    tr.save(filename.c_str());
./mpi/p4est_save_03.cc:18:// save and load a triangulation with two solution vectors
./mpi/p4est_save_03.cc:107:    tr.save (filename.c_str());
./mpi/p4est_save_04.cc:18:// save and load a triangulation with a different number of cpus
./mpi/p4est_save_04.cc:99:      tr.save ("file");
./serialization/serialization.h:48:  // save data to archive
./sharedtria/tria_load_01.cc:17:// save a tria mesh and load it
./sharedtria/tria_load_01.cc:46:    tr1.save(oa, 0);
./slepc/step-36_parallel.cc:35:const unsigned int dim = 2;//run in 2d to save time

and its the test in "mpi/p4est_save_03.cc" that seems to demonstrate the capabilities that you're looking for.

Regards,
Jean-Paul

Wolfgang Bangerth

unread,
Nov 7, 2016, 1:25:02 AM11/7/16
to dea...@googlegroups.com
On 11/06/2016 06:43 PM, Anup Basak wrote:
>
> I shall be thankful if someone could tell me in details how to use 'save()'
> and 'load()' functions to save and load
> triangulation information and the nodal values of displacements, strains,
> stresses, and may be temperature
> (similar to step44) so that they can be used as initial data in another
> simulations with the identical triangulation data.
>
> Or if there is some other simpler way.

Anup,
in addition to the testcases just pointed out, there is also the code in
ASPECT that uses this functionality:

https://github.com/geodynamics/aspect/blob/master/source/simulator/checkpoint_restart.cc
This is of course a much larger project, but it may still help you understand
how things are used in practice.

Best
W.


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

Anup Basak

unread,
Nov 7, 2016, 9:39:40 AM11/7/16
to deal.II User Group
Thank you Jean-Paul and Prof. Bangerth for the references. I will work on it now.

Regards,
Anup.

Anup Basak

unread,
Nov 7, 2016, 8:11:31 PM11/7/16
to dea...@googlegroups.com
Hello all,

It seems that to work with load() and save() one needs to work with boost packages.
I was wondering if it is already inbuilt in dealii packages or I need to install boost and build it
separately.

Thanks,
Anup.

--

Wolfgang Bangerth

unread,
Nov 7, 2016, 8:31:08 PM11/7/16
to dea...@googlegroups.com
On 11/07/2016 06:11 PM, Anup Basak wrote:
>
> It seems that to work with load() and save() one needs to work with boost
> packages.
> I was wondering if it is already inbuilt in dealii packages or I need to
> install boost and build it
> separately.

It's all there already, ready for you to use :-)

Anup Basak

unread,
Nov 8, 2016, 2:36:54 PM11/8/16
to deal.II User Group, bang...@colostate.edu
Hello all,

It seems that using block_write() and block_read would be easier to store data and reuse them
as initial conditions on identical geometry and mesh compared to using boost:serialization. However,
I have some issues and quires (I do not use parallelization in my code). I shall be thankful if someone
clarifies the following things:

(i) Suppose I want to store my 'Solution' vector to the zeroth block of a BlockVector 'solution_save'.
For that I have used the following command (in blue) and I get error (in red). It seems that the first
line is not the correct way to store vectors in the block. Can you please let me know the correct command?

solution_save.block(0) = solution;
std::ofstream output_text("data.txt");
solution_save.block_write(output_text);


/home/abasak/Desktop/Anup/dealiicodes/myprogs/junks/step-26/step-26.cc:338:28: error: no match for ‘operator=’ (operand types are ‘const BlockType {aka const dealii::Vector<double>}’ and ‘const dealii::Vector<double>’)
     solution_save.block(0) = solution;


2. I am solving mechanics problem. So I need to store the stress and strain tensors at each node as well. I was wondering if it is possible to store
the tensors somehow. One possibility could be, I think, to store all nine (here six) components in different blocks and reunite them while reading. But is there a smarter way to store tensors?

3. Also, I must save the triangulation and all nodal and element information. How to go about it?

Many thanks,

Regards,
Anup.

Wolfgang Bangerth

unread,
Nov 8, 2016, 3:57:30 PM11/8/16
to Anup Basak, deal.II User Group
> It seems that using block_write() and block_read would be easier to store data
> and reuse them
> as initial conditions on identical geometry and mesh compared to using
> boost:serialization.

In sequential computations, that is probably true.

> (i) Suppose I want to store my 'Solution' vector to the zeroth block of a
> BlockVector 'solution_save'.
> For that I have used the following command (in blue) and I get error (in red).
> It seems that the first
> line is not the correct way to store vectors in the block. Can you please let
> me know the correct command?
>
> solution_save.block(0) = solution;
> std::ofstream output_text("data.txt");
> solution_save.block_write(output_text);
>
> /home/abasak/Desktop/Anup/dealiicodes/myprogs/junks/step-26/step-26.cc:338:28:
> error: no match for ‘operator=’ (operand types are ‘const BlockType {aka const
> dealii::Vector<double>}’ and ‘const dealii::Vector<double>’)
> solution_save.block(0) = solution;

The left hand side vector is *const*. You can't assign anything to it.

It may be const because you declare it const, or because it is a member
variable but you are in a function that is marked as "const".


> 2. I am solving mechanics problem. So I need to store the stress and strain
> tensors at each node as well. I was wondering if it is possible to store
> the tensors somehow. One possibility could be, I think, to store all nine
> (here six) components in different blocks and reunite them while reading. But
> is there a smarter way to store tensors?

Why don't you just loop over all cells, over all quadrature points, and
serialize all of your data into a stream, e.g., by just writing them as
regular data. Then, upon loading, you can just reverse the operation by
reading from the stream.


> 3. Also, I must save the triangulation and all nodal and element information.
> How to go about it?

That is where you should use the boost serialization functionality others have
already pointed you to.

Best
Reply all
Reply to author
Forward
0 new messages