dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #03425
Re: VTK and discontinuous elements
Hi,
I did some changes in OpenDXFile.cpp in order to work with triangles.
Let's see the attachment for both source code and the DX net file.
Regards,
/ Minh
Dag Lindbo wrote:
Hi all,
Am I right to conclude that Paraview will fail to produce a sensible
visualization of a function on a discontinuous Lagrange element of order >
0? I guess this has to do with how the degrees of freedom are placed on
such an element. Anyway, it's not very important for me to do these
visualizations - but if someone has a neat way to do it I would be glad to
hear.
By the way, is there a particular reason for only supporting tetrahedral
cells in the OpenDX output format? If not, I might get around to extending
to triangles (since I really like DX).
Best regards,
Dag Lindbo
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev
// Copyright (C) 2003-2006 Johan Hoffman and Anders Logg.
// Licensed under the GNU GPL Version 2.
//
// Modified by Minh Do-Quang 2006
//
// First added: 2003-07-15
// Last changed: 2006-09-15
#include <stdio.h>
#include <dolfin/ParameterSystem.h>
#include <dolfin/Mesh.h>
#include <dolfin/Function.h>
#include <dolfin/dolfin_log.h>
#include <dolfin/OpenDXFile.h>
using namespace dolfin;
//----------------------------------------------------------------------------
OpenDXFile::OpenDXFile(const std::string filename) :
GenericFile(filename),
save_each_mesh(dolfin::get("save each mesh")),
event_saving_mesh("Saving mesh to OpenDX file."),
event_saving_function("Saving function to OpenDX file.")
{
type = "OpenDX";
series_pos = 0;
}
//----------------------------------------------------------------------------
OpenDXFile::~OpenDXFile()
{
// Do nothing
}
//----------------------------------------------------------------------------
void OpenDXFile::operator<<(Mesh& mesh)
{
event_saving_mesh();
// Open file
FILE* fp = fopen(filename.c_str(), "r+");
fseek(fp, 0L, SEEK_END);
// Write header first time
if ( ftell(fp) == 0 )
writeHeader(fp);
// Write mesh
writeMesh(fp, mesh);
// Write mesh data
writeMeshData(fp, mesh);
// Close file
fclose(fp);
}
//----------------------------------------------------------------------------
void OpenDXFile::operator<<(Function& u)
{
event_saving_function();
// Open file
FILE* fp = fopen(filename.c_str(), "r+");
fseek(fp, 0L, SEEK_END);
// Remove previous time series
if ( frames.size() > 0 )
removeSeries(fp);
// Write header first time
if ( ftell(fp) == 0 )
writeHeader(fp);
// Write mesh
if ( frames.size() == 0 || save_each_mesh )
writeMesh(fp, u.mesh());
// Write function
writeFunction(fp, u);
// Write time series
writeSeries(fp, u);
// Close file
fclose(fp);
}
//----------------------------------------------------------------------------
void OpenDXFile::writeHeader(FILE* fp)
{
fprintf(fp,"# Output from DOLFIN version %s.\n", DOLFIN_VERSION);
fprintf(fp,"# Format intended for use with OpenDX (Data Explorer).\n");
fprintf(fp,"#\n");
fprintf(fp,"\n");
}
//----------------------------------------------------------------------------
void OpenDXFile::writeMesh(FILE* fp, Mesh& mesh)
{
int meshdim, celldim;
if( mesh.type() == Mesh::tetrahedra ) {
meshdim = 3;
celldim = 4;
} else {
meshdim = 2;
celldim = 3;
}
// Write vertices
fprintf(fp, "# A list of all vertex positions\n");
fprintf(fp, "object \"vertices %d\" class array type float rank 1 shape %d items %d lsb binary data follows\n",
(int)frames.size(), meshdim, mesh.numVertices());
for (VertexIterator n(mesh); !n.end(); ++n)
{
Point p = n->coord();
float x = (float) p.x;
float y = (float) p.y;
float z = (float) p.z;
fwrite(&x, sizeof(float), 1, fp);
fwrite(&y, sizeof(float), 1, fp);
if ( mesh.type() == Mesh::tetrahedra )
fwrite(&z, sizeof(float), 1, fp);
}
fprintf(fp,"\n\n");
// Write cells
fprintf(fp, "# A list of all cells (connections)\n");
fprintf(fp, "object \"cells %d\" class array type int rank 1 shape %d items %d lsb binary data follows\n",
(int)frames.size(), celldim, mesh.numCells());
for (CellIterator c(mesh); !c.end(); ++c)
{
for (VertexIterator n(c); !n.end(); ++n)
{
int id = n->id();
fwrite(&id, sizeof(int), 1, fp);
}
}
fprintf(fp, "\n");
if ( mesh.type() == Mesh::tetrahedra )
fprintf(fp, "attribute \"element type\" string \"tetrahedra\"\n");
else if ( mesh.type() == Mesh::triangles )
fprintf(fp, "attribute \"element type\" string \"triangles\"\n");
fprintf(fp, "attribute \"ref\" string \"positions\"\n");
fprintf(fp, "\n");
}
//----------------------------------------------------------------------------
void OpenDXFile::writeMeshData(FILE* fp, Mesh& mesh)
{
// Write data for a given mesh to create an object that can be visualized
// when no data is associated with the mesh. This is necessary when we only
// want to save the mesh.
// Check that we don't try to write mesh data at the same time as we
// write a time series
cout << "writeMeshData "<<frames.size()<<endl;
if ( frames.size() > 0 )
dolfin_error("Mesh data and time series cannot be mixed for OpenDX file format.");
// Write data (cell diameter)
fprintf(fp,"# Cell diameter\n");
fprintf(fp,"object \"diameter\" class array type float rank 0 items %d lsb binary data follows\n",
mesh.numCells());
for (CellIterator c(mesh); !c.end(); ++c)
{
float value = static_cast<float>(c->diameter());
fwrite(&value, sizeof(float), 1, fp);
}
fprintf(fp, "\n");
fprintf(fp, "attribute \"dep\" string \"connections\"\n");
fprintf(fp, "\n");
// Write the mesh
fprintf(fp, "# The mesh\n");
fprintf(fp, "object \"Mesh\" class field\n");
fprintf(fp, "component \"positions\" value \"vertices 0\"\n");
fprintf(fp, "component \"connections\" value \"cells 0\"\n");
fprintf(fp, "component \"data\" value \"diameter\"\n");
}
//----------------------------------------------------------------------------
void OpenDXFile::writeFunction(FILE* fp, Function& u)
{
// Write header for object
fprintf(fp,"# Values for [%s] at nodal points, frame %d\n", u.label().c_str(), (int)frames.size());
fprintf(fp,"object \"data %d\" class array type float rank 1 shape %d items %d lsb binary data follows\n",
(int)frames.size(), u.vectordim(), u.mesh().numVertices());
// Write data
for (VertexIterator n(u.mesh()); !n.end(); ++n)
{
for(unsigned int i=0; i<u.vectordim(); i++) {
float value = static_cast<float>(u(*n, i));
fwrite(&value, sizeof(float), 1, fp);
}
}
fprintf(fp,"\n");
fprintf(fp,"attribute \"dep\" string \"positions\"\n\n");
// Write field
fprintf(fp,"# Field for [%s], frame %d\n", u.label().c_str(), (int)frames.size());
fprintf(fp,"object \"field %d\" class field\n", (int)frames.size());
if ( save_each_mesh )
fprintf(fp,"component \"positions\" value \"vertices %d\"\n", (int)frames.size());
else
fprintf(fp,"component \"positions\" value \"vertices 0\"\n");
if ( save_each_mesh )
fprintf(fp,"component \"connections\" value \"cells %d\"\n", (int)frames.size());
else
fprintf(fp,"component \"connections\" value \"cells 0\"\n");
fprintf(fp,"component \"data\" value \"data %d\"\n\n", (int)frames.size());
// Add the new frame
Frame frame(u.time());
frames.push_back(frame);
}
//----------------------------------------------------------------------------
void OpenDXFile::writeSeries(FILE* fp, Function& u)
{
// Get position in file at start of series
series_pos = ftell(fp);
// Write the time series
fprintf(fp,"# Time series for [%s]\n", u.label().c_str());
fprintf(fp,"object \"Time series\" class series\n");
for (unsigned int i = 0; i < frames.size(); i++)
{
fprintf(fp,"member %u value \"field %u\" position %f\n",
i, i, frames[i].time);
}
fprintf(fp,"\n");
}
//----------------------------------------------------------------------------
void OpenDXFile::removeSeries(FILE* fp)
{
// Remove the previous series (the new one will be placed at the end).
// This makes sure that we have a valid dx-file even if we kill the
// program after a few frames. Note that if someone puts a "#"
// inside a comment we are in trouble.
fseek(fp, series_pos, SEEK_SET);
fflush(fp);
}
//----------------------------------------------------------------------------
// OpenDXFile::Frame
//----------------------------------------------------------------------------
OpenDXFile::Frame::Frame(real time) : time(time)
{
// Do nothing
}
//----------------------------------------------------------------------------
OpenDXFile::Frame::~Frame()
{
// Do nothing
}
//
// time: Fri Sep 15 17:50:13 2006
//
// version: 3.2.0 (format), 4.4.0 (DX)
//
//
// MODULE main
// workspace: width = 389, height = 294
// layout: snap = 0, width = 50, height = 50, align = NN
//
macro main(
) -> (
) {
//
// node Import[1]: x = 24, y = 23, inputs = 6, label = Import
// input[1]: defaulting = 0, visible = 1, type = 32, value = "poisson.dx"
// input[2]: defaulting = 0, visible = 1, type = 32, value = "field 0"
//
main_Import_1_out_1 =
Import(
main_Import_1_in_1,
main_Import_1_in_2,
main_Import_1_in_3,
main_Import_1_in_4,
main_Import_1_in_5,
main_Import_1_in_6
) [instance: 1, cache: 1];
//
// node AutoColor[1]: x = 174, y = 232, inputs = 10, label = AutoColor
//
main_AutoColor_1_out_1,
main_AutoColor_1_out_2 =
AutoColor(
main_Import_1_out_1,
main_AutoColor_1_in_2,
main_AutoColor_1_in_3,
main_AutoColor_1_in_4,
main_AutoColor_1_in_5,
main_AutoColor_1_in_6,
main_AutoColor_1_in_7,
main_AutoColor_1_in_8,
main_AutoColor_1_in_9,
main_AutoColor_1_in_10
) [instance: 1, cache: 1];
//
// node Image[1]: x = 311, y = 218, inputs = 49, label = Image
// input[1]: defaulting = 0, visible = 0, type = 32, value = "Image_1"
// input[4]: defaulting = 0, visible = 0, type = 1, value = 1
// input[5]: defaulting = 0, visible = 0, type = 8, value = [0.5 0.5 0]
// input[6]: defaulting = 0, visible = 0, type = 8, value = [0.5 0.5 3.55379]
// input[7]: defaulting = 0, visible = 0, type = 5, value = 1.90447
// input[8]: defaulting = 0, visible = 0, type = 1, value = 640
// input[9]: defaulting = 0, visible = 0, type = 5, value = 0.75
// input[10]: defaulting = 0, visible = 0, type = 8, value = [0 1 0]
// input[11]: defaulting = 1, visible = 0, type = 5, value = 30.0
// input[12]: defaulting = 0, visible = 0, type = 1, value = 0
// input[14]: defaulting = 0, visible = 0, type = 1, value = 1
// input[15]: defaulting = 1, visible = 0, type = 32, value = "none"
// input[16]: defaulting = 1, visible = 0, type = 32, value = "none"
// input[17]: defaulting = 1, visible = 0, type = 1, value = 1
// input[18]: defaulting = 1, visible = 0, type = 1, value = 1
// input[19]: defaulting = 0, visible = 0, type = 1, value = 0
// input[29]: defaulting = 1, visible = 0, type = 3, value = 0
// depth: value = 24
// window: position = (0.5419,0.4650), size = 0.4088x0.4350
// internal caching: 1
// interaction mode = NONE
//
main_Image_1_out_1,
main_Image_1_out_2,
main_Image_1_out_3 =
Image(
main_Image_1_in_1,
main_AutoColor_1_out_1,
main_Image_1_in_3,
main_Image_1_in_4,
main_Image_1_in_5,
main_Image_1_in_6,
main_Image_1_in_7,
main_Image_1_in_8,
main_Image_1_in_9,
main_Image_1_in_10,
main_Image_1_in_11,
main_Image_1_in_12,
main_Image_1_in_13,
main_Image_1_in_14,
main_Image_1_in_15,
main_Image_1_in_16,
main_Image_1_in_17,
main_Image_1_in_18,
main_Image_1_in_19,
main_Image_1_in_20,
main_Image_1_in_21,
main_Image_1_in_22,
main_Image_1_in_23,
main_Image_1_in_24,
main_Image_1_in_25,
main_Image_1_in_26,
main_Image_1_in_27,
main_Image_1_in_28,
main_Image_1_in_29,
main_Image_1_in_30,
main_Image_1_in_31,
main_Image_1_in_32,
main_Image_1_in_33,
main_Image_1_in_34,
main_Image_1_in_35,
main_Image_1_in_36,
main_Image_1_in_37,
main_Image_1_in_38,
main_Image_1_in_39,
main_Image_1_in_40,
main_Image_1_in_41,
main_Image_1_in_42,
main_Image_1_in_43,
main_Image_1_in_44,
main_Image_1_in_45,
main_Image_1_in_46,
main_Image_1_in_47,
main_Image_1_in_48,
main_Image_1_in_49
) [instance: 1, cache: 1];
//
// node Print[1]: x = 33, y = 119, inputs = 3, label = Print
// input[2]: defaulting = 0, visible = 1, type = 32, value = "o"
//
Print(
main_Import_1_out_1,
main_Print_1_in_2,
main_Print_1_in_3
) [instance: 1, cache: 1];
//
// node Select[1]: x = 154, y = 106, inputs = 3, label = Select
// input[2]: defaulting = 0, visible = 1, type = 32, value = "field 0"
//
main_Select_1_out_1 =
Select(
main_Import_1_out_1,
main_Select_1_in_2,
main_Select_1_in_3
) [instance: 1, cache: 1];
//
// node ShowConnections[1]: x = 256, y = 79, inputs = 1, label = ShowConnections
//
main_ShowConnections_1_out_1 =
ShowConnections(
main_Import_1_out_1
) [instance: 1, cache: 1];
// network: end of macro body
CacheScene(main_Image_1_in_1, main_Image_1_out_1, main_Image_1_out_2);
}
main_Import_1_in_1 = "poisson.dx";
main_Import_1_in_2 = "field 0";
main_Import_1_in_3 = NULL;
main_Import_1_in_4 = NULL;
main_Import_1_in_5 = NULL;
main_Import_1_in_6 = NULL;
main_Import_1_out_1 = NULL;
main_AutoColor_1_in_2 = NULL;
main_AutoColor_1_in_3 = NULL;
main_AutoColor_1_in_4 = NULL;
main_AutoColor_1_in_5 = NULL;
main_AutoColor_1_in_6 = NULL;
main_AutoColor_1_in_7 = NULL;
main_AutoColor_1_in_8 = NULL;
main_AutoColor_1_in_9 = NULL;
main_AutoColor_1_in_10 = NULL;
main_AutoColor_1_out_1 = NULL;
macro Image(
id,
object,
where,
useVector,
to,
from,
width,
resolution,
aspect,
up,
viewAngle,
perspective,
options,
buttonState = 1,
buttonUpApprox = "none",
buttonDownApprox = "none",
buttonUpDensity = 1,
buttonDownDensity = 1,
renderMode = 0,
defaultCamera,
reset,
backgroundColor,
throttle,
RECenable = 0,
RECfile,
RECformat,
RECresolution,
RECaspect,
AAenable = 0,
AAlabels,
AAticks,
AAcorners,
AAframe,
AAadjust,
AAcursor,
AAgrid,
AAcolors,
AAannotation,
AAlabelscale,
AAfont,
interactionMode,
title,
AAxTickLocs,
AAyTickLocs,
AAzTickLocs,
AAxTickLabels,
AAyTickLabels,
AAzTickLabels,
webOptions) -> (
object,
camera,
where)
{
ImageMessage(
id,
backgroundColor,
throttle,
RECenable,
RECfile,
RECformat,
RECresolution,
RECaspect,
AAenable,
AAlabels,
AAticks,
AAcorners,
AAframe,
AAadjust,
AAcursor,
AAgrid,
AAcolors,
AAannotation,
AAlabelscale,
AAfont,
AAxTickLocs,
AAyTickLocs,
AAzTickLocs,
AAxTickLabels,
AAyTickLabels,
AAzTickLabels,
interactionMode,
title,
renderMode,
buttonUpApprox,
buttonDownApprox,
buttonUpDensity,
buttonDownDensity) [instance: 1, cache: 1];
autoCamera =
AutoCamera(
object,
"front",
object,
resolution,
aspect,
[0,1,0],
perspective,
viewAngle,
backgroundColor) [instance: 1, cache: 1];
realCamera =
Camera(
to,
from,
width,
resolution,
aspect,
up,
perspective,
viewAngle,
backgroundColor) [instance: 1, cache: 1];
coloredDefaultCamera =
UpdateCamera(defaultCamera,
background=backgroundColor) [instance: 1, cache: 1];
nullDefaultCamera =
Inquire(defaultCamera,
"is null + 1") [instance: 1, cache: 1];
resetCamera =
Switch(
nullDefaultCamera,
coloredDefaultCamera,
autoCamera) [instance: 1, cache: 1];
resetNull =
Inquire(
reset,
"is null + 1") [instance: 2, cache: 1];
reset =
Switch(
resetNull,
reset,
0) [instance: 2, cache: 1];
whichCamera =
Compute(
"($0 != 0 || $1 == 0) ? 1 : 2",
reset,
useVector) [instance: 1, cache: 1];
camera = Switch(
whichCamera,
resetCamera,
realCamera) [instance: 3, cache: 1];
AAobject =
AutoAxes(
object,
camera,
AAlabels,
AAticks,
AAcorners,
AAframe,
AAadjust,
AAcursor,
AAgrid,
AAcolors,
AAannotation,
AAlabelscale,
AAfont,
AAxTickLocs,
AAyTickLocs,
AAzTickLocs,
AAxTickLabels,
AAyTickLabels,
AAzTickLabels) [instance: 1, cache: 1];
switchAAenable = Compute("$0+1",
AAenable) [instance: 2, cache: 1];
object = Switch(
switchAAenable,
object,
AAobject) [instance:4, cache: 1];
SWapproximation_options =
Switch(
buttonState,
buttonUpApprox,
buttonDownApprox) [instance: 5, cache: 1];
SWdensity_options =
Switch(
buttonState,
buttonUpDensity,
buttonDownDensity) [instance: 6, cache: 1];
HWapproximation_options =
Format(
"%s,%s",
buttonDownApprox,
buttonUpApprox) [instance: 1, cache: 1];
HWdensity_options =
Format(
"%d,%d",
buttonDownDensity,
buttonUpDensity) [instance: 2, cache: 1];
switchRenderMode = Compute(
"$0+1",
renderMode) [instance: 3, cache: 1];
approximation_options = Switch(
switchRenderMode,
SWapproximation_options,
HWapproximation_options) [instance: 7, cache: 1];
density_options = Switch(
switchRenderMode,
SWdensity_options,
HWdensity_options) [instance: 8, cache: 1];
renderModeString = Switch(
switchRenderMode,
"software",
"hardware")[instance: 9, cache: 1];
object_tag = Inquire(
object,
"object tag")[instance: 3, cache: 1];
annoted_object =
Options(
object,
"send boxes",
0,
"cache",
1,
"object tag",
object_tag,
"ddcamera",
whichCamera,
"rendering approximation",
approximation_options,
"render every",
density_options,
"button state",
buttonState,
"rendering mode",
renderModeString) [instance: 1, cache: 1];
RECresNull =
Inquire(
RECresolution,
"is null + 1") [instance: 4, cache: 1];
ImageResolution =
Inquire(
camera,
"camera resolution") [instance: 5, cache: 1];
RECresolution =
Switch(
RECresNull,
RECresolution,
ImageResolution) [instance: 10, cache: 1];
RECaspectNull =
Inquire(
RECaspect,
"is null + 1") [instance: 6, cache: 1];
ImageAspect =
Inquire(
camera,
"camera aspect") [instance: 7, cache: 1];
RECaspect =
Switch(
RECaspectNull,
RECaspect,
ImageAspect) [instance: 11, cache: 1];
switchRECenable = Compute(
"$0 == 0 ? 1 : (($2 == $3) && ($4 == $5)) ? ($1 == 1 ? 2 : 3) : 4",
RECenable,
switchRenderMode,
RECresolution,
ImageResolution,
RECaspect,
ImageAspect) [instance: 4, cache: 1];
NoRECobject, RECNoRerenderObject, RECNoRerHW, RECRerenderObject = Route(switchRECenable, annoted_object);
Display(
NoRECobject,
camera,
where,
throttle) [instance: 1, cache: 1];
image =
Render(
RECNoRerenderObject,
camera) [instance: 1, cache: 1];
Display(
image,
NULL,
where,
throttle) [instance: 2, cache: 1];
WriteImage(
image,
RECfile,
RECformat) [instance: 1, cache: 1];
rec_where = Display(
RECNoRerHW,
camera,
where,
throttle) [instance: 1, cache: 0];
rec_image = ReadImageWindow(
rec_where) [instance: 1, cache: 1];
WriteImage(
rec_image,
RECfile,
RECformat) [instance: 1, cache: 1];
RECupdateCamera =
UpdateCamera(
camera,
resolution=RECresolution,
aspect=RECaspect) [instance: 2, cache: 1];
Display(
RECRerenderObject,
camera,
where,
throttle) [instance: 1, cache: 1];
RECRerenderObject =
ScaleScreen(
RECRerenderObject,
NULL,
RECresolution,
camera) [instance: 1, cache: 1];
image =
Render(
RECRerenderObject,
RECupdateCamera) [instance: 2, cache: 1];
WriteImage(
image,
RECfile,
RECformat) [instance: 2, cache: 1];
}
main_Image_1_in_1 = "Image_1";
main_Image_1_in_3 = "X24,,";
main_Image_1_in_4 = 1;
main_Image_1_in_5 = [0.5 0.5 0];
main_Image_1_in_6 = [0.5 0.5 3.55379];
main_Image_1_in_7 = 1.90447;
main_Image_1_in_8 = 640;
main_Image_1_in_9 = 0.75;
main_Image_1_in_10 = [0 1 0];
main_Image_1_in_11 = NULL;
main_Image_1_in_12 = 0;
main_Image_1_in_13 = NULL;
main_Image_1_in_14 = 1;
main_Image_1_in_15 = NULL;
main_Image_1_in_16 = NULL;
main_Image_1_in_17 = NULL;
main_Image_1_in_18 = NULL;
main_Image_1_in_19 = 0;
main_Image_1_in_20 = NULL;
main_Image_1_in_21 = NULL;
main_Image_1_in_22 = NULL;
main_Image_1_in_23 = NULL;
main_Image_1_in_25 = NULL;
main_Image_1_in_26 = NULL;
main_Image_1_in_27 = NULL;
main_Image_1_in_28 = NULL;
main_Image_1_in_29 = NULL;
main_Image_1_in_30 = NULL;
main_Image_1_in_31 = NULL;
main_Image_1_in_32 = NULL;
main_Image_1_in_33 = NULL;
main_Image_1_in_34 = NULL;
main_Image_1_in_35 = NULL;
main_Image_1_in_36 = NULL;
main_Image_1_in_37 = NULL;
main_Image_1_in_38 = NULL;
main_Image_1_in_39 = NULL;
main_Image_1_in_40 = NULL;
main_Image_1_in_41 = NULL;
main_Image_1_in_42 = NULL;
main_Image_1_in_43 = NULL;
main_Image_1_in_44 = NULL;
main_Image_1_in_45 = NULL;
main_Image_1_in_46 = NULL;
main_Image_1_in_47 = NULL;
main_Image_1_in_48 = NULL;
main_Image_1_in_49 = NULL;
main_Print_1_in_2 = "o";
main_Print_1_in_3 = NULL;
main_Select_1_in_2 = "field 0";
main_Select_1_in_3 = NULL;
Executive("product version 4 4 0");
$sync
main();
Follow ups