GiDpost

Moderator: GiD Team

Malte von Scheven

GiDpost

Post by Malte von Scheven »

Hello,

I am trying to use the GiDpost library to create output in txt or binary
format. For normal output it works fine, but when I try to use mesh
groups GiDpost returns an error when I call

GiD_fBeginMeshGroup(fdm, buffer);

Assertion failed: CheckState(POST_S0,File-level_mesh), file gidpost.c,
line 591
invalid state 'UNDEFINED level' should be 'TOP level'

Before that I used

GiD_PostInit();
fdm = GiD_fOpenPostMeshFile( filename, GiD_PostAscii);

to open the mesh file.

Is there any other command I have to call before I can begin a mesh
group? Unfortunately I could not find any further information in the
documentation and the examples.

Thanks a lot for your advice!

Regards
Malte
Malte von Scheven

GiDpost

Post by Malte von Scheven »

Hello,

to me the problem is still unsolved.

I have generated a small example program (based on the example provided
with GiDpost) that demonstrates the problem.

The code runs fine without groups. But when activating the groups
(#define USE_MESH_GROUP) it shows the error described below.

The error is only shown for the ASCII format, when I use groups in
binary format the file created and can be opened with GiD at least for
one group.

Regards
Malte
User avatar
ronda
Posts: 8
Joined: Mon Oct 13, 2014 9:29 am

GiDpost

Post by ronda »

Hello, could you send us the code?

best regards,

Jorge
Malte von Scheven

GiDpost

Post by Malte von Scheven »

Sorry, I forgot the attachment :)

Regards
Malte

----------------------------------------------

Code: Select all

#include stdlib.h
#include "gidpost.h"


#define ASCII_FORMAT
#define USE_MESH_GROUP


typedef struct {
  int id;
  float x, y, z;
} SCoord;

typedef struct {
  int id;
  int n1, n2, n3;
} SElem;

SCoord nodes[9];
SElem elems[8];

void GenMesh()
{
  int i, j, idx;
  SCoord * node;
  SElem * elm1, * elm2;

  idx = 1;
  for ( i = 0; i  3; i++ ) {
    for ( j = 0; j  3; j++, idx++ ) {
      node = nodes + idx -1;
      node-id = idx;
      node-x = (float)(i);
      node-y = (float)(j);
      node-z = 0;
    }
  }
  idx = 0;
  for ( i = 0; i  2; i++ ) {
    for ( j = 0; j  2; j++, idx+=2 ) {
      elm1 = elems + idx;
      elm2 = elm1 + 1;
      elm1-id = idx+1;
      elm1-n1 = i*3 + j + 1;
      elm1-n3 = i*3 + j + 1 + 3 ;
      elm1-n2 = elm1-n3 + 1;
      elm2-id = idx+2;
      elm2-n1 = elm1-n1;
      elm2-n2 = elm1-n1 + 1;
      elm2-n3 = elm1-n2;
    }
  }
}

float Random()
{
  return rand()/(float)(RAND_MAX);
}

int main()
{
  int i;
  SCoord * node;
  SElem * elm;
  int elmi[4];
  int elmi2[10];
  GiD_FILE fdm, fdr;

  GenMesh();

  GiD_PostInit();

#if defined(ASCII_FORMAT)
  fdm = GiD_fOpenPostMeshFile( "test_fd.post.msh", GiD_PostAscii);
  fdr = GiD_fOpenPostResultFile( "test_fd.post.res", GiD_PostAscii);
#else
  fdm = fdr = GiD_fOpenPostResultFile( "test_fd.post.bin", GiD_PostBinary);
#endif







  /* write mesh info */

  // TODO START MESHGROUP
#ifdef USE_MESH_GROUP
  GiD_fBeginMeshGroup(fdm, "Mesh 1");
#endif


  GiD_fBeginMeshColor(fdm, "TestMsh", GiD_2D, GiD_Triangle, 3, 0, 0.99, 0);
  /* coordinates */
  GiD_fBeginCoordinates(fdm);
  for ( i = 0; i  9; i++ ) {
    node = nodes + i;
    GiD_fWriteCoordinates(fdm, node-id, node-x, node-y, node-z );
  }
  GiD_fEndCoordinates(fdm);
  /* elements */
  GiD_fBeginElements(fdm);
  for ( i = 0; i  8; i++ ) {
    elm = elems + i;
    elmi[0] = elm-n1;
    elmi[1] = elm-n2;
    elmi[2] = elm-n3;
    elmi[3] = 2;
    GiD_fWriteElementMat(fdm, elm-id, elmi);
  }
  GiD_fEndElements(fdm);
  GiD_fEndMesh(fdm);


  // TODO END MESHGROUP
#ifdef USE_MESH_GROUP
  GiD_fEndMeshGroup(fdm);
#endif






  /* now results info */


  // TODO Start ONMESHGROUP
#ifdef USE_MESH_GROUP
  GiD_fBeginOnMeshGroup(fdr, "Mesh 1");
#endif

  GiD_fBeginResult(fdr, "EscalarNodos", "Analysis", 1.0, GiD_Scalar, GiD_OnNodes, NULL, NULL, 0, NULL);
  for ( i = 0; i  9; i++ ) {
    GiD_fWriteScalar(fdr, nodes[i].id, Random());
  }
  GiD_fEndResult(fdr);

  // TODO END MESHGROUP
#ifdef USE_MESH_GROUP
  GiD_fEndOnMeshGroup(fdr);
#endif




#ifdef ASCII_FORMAT
  GiD_fClosePostMeshFile(fdm);
#endif
  GiD_fClosePostResultFile(fdr);

  GiD_PostDone();

  return 0;
}
User avatar
ronda
Posts: 8
Joined: Mon Oct 13, 2014 9:29 am

GiDpost

Post by ronda »

Hello, regarding your issue, we have reproduced the bug and we are working
on a fix.

Thanks for the example.

best regards,

Jorge
User avatar
ronda
Posts: 8
Joined: Mon Oct 13, 2014 9:29 am

GiDpost

Post by ronda »

Hi Malte, we have made some fix related to your issue in Gidpost. Attached
you can find the source code with the corrections. Could you give it a try
an let me know if that fix your issue?. As a side effect now we are
starting to introduce son constants to recognize the error codes returned
by the functions. This last change is still under development.

After we confirm the fix we are going to release an official release of the
lib.

best regards,

Jorge
Malte von Scheven

GiDpost

Post by Malte von Scheven »

Hi Jorge,

thanks a lot for your effort, but for me it does not work.

Using my small example I sent you, the new version works fine without
mesh groups, but defining the symbol USE_MESH_GROUP the execution stops
on line 139 "GiD_fEndResult(fdr);" for both binary and ascii output.

The error message is:

Assertion failed: CheckState( POST_S0, File ), file
gidpost2.3\source\gidpost.c, line 2291

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
Current State = MESHGROUP header
invalid state 'OnGroup block' should be 'TOP level'

Best Regards
Malte
mvscheven
Posts: 16
Joined: Thu Dec 04, 2014 4:26 pm
Location: Stuttgart, Germany

Re: GiDpost

Post by mvscheven »

Hi Jorge,

Your new version of GiDpost solved most of the problems. My example now runs with one group for ASCII and binary output and I can open the output with GiD.

I have now extended the example to two groups with different meshes (original triangles in the first mesh and one q2 element in the second mesh). See the following code.

Code: Select all

#include <stdlib.h>
#include <stdio.h>
#include "gidpost.h"

#define ASCII_FORMAT

typedef struct {
  int id;
  float x, y, z;
} SCoord;

typedef struct {
  int id;
  int n1, n2, n3;
} SElem;

SCoord nodes[9];
SElem elems[8];

void GenMesh()
{
  int i, j, idx;
  SCoord * node;
  SElem * elm1, * elm2;

  idx = 1;
  for ( i = 0; i < 3; i++ ) {
    for ( j = 0; j < 3; j++, idx++ ) {
      node = nodes + idx -1;
      node->id = idx;
      node->x = (float)(i);
      node->y = (float)(j);
      node->z = 0;
    }
  }
  idx = 0;
  for ( i = 0; i < 2; i++ ) {
    for ( j = 0; j < 2; j++, idx+=2 ) {
      elm1 = elems + idx;
      elm2 = elm1 + 1;
      elm1->id = idx+1;
      elm1->n1 = i*3 + j + 1;
      elm1->n3 = i*3 + j + 1 + 3 ;
      elm1->n2 = elm1->n3 + 1;
      elm2->id = idx+2;
      elm2->n1 = elm1->n1;
      elm2->n2 = elm1->n1 + 1;
      elm2->n3 = elm1->n2;
    }
  }
}

float Random()
{
  return rand()/(float)(RAND_MAX);
}

int main()
{
  int i;
  SCoord * node;
  SElem * elm;
  int elmi[4];
  int elmi2[10];
  GiD_FILE fdm, fdr;

  GenMesh();

  GiD_PostInit();

#if defined(ASCII_FORMAT)
  fdm = GiD_fOpenPostMeshFile( "test_fd.post.msh", GiD_PostAscii);
  fdr = GiD_fOpenPostResultFile( "test_fd.post.res", GiD_PostAscii);
#else
  fdm = fdr = GiD_fOpenPostResultFile( "test_fd.post.bin", GiD_PostBinary);
#endif



  /* write mesh for first time step */
  GiD_fBeginMeshGroup(fdm, "Mesh 1");

  GiD_fBeginMeshColor(fdm, "TestMsh", GiD_2D, GiD_Triangle, 3, 0, 0.99, 0);
  /* coordinates */
  GiD_fBeginCoordinates(fdm);
  for ( i = 0; i < 9; i++ ) {
    node = nodes + i;
    GiD_fWriteCoordinates(fdm, node->id, node->x, node->y, node->z );
  }
  GiD_fEndCoordinates(fdm);
  /* elements */
  GiD_fBeginElements(fdm);
  for ( i = 0; i < 8; i++ ) {
    elm = elems + i;
    elmi[0] = elm->n1;
    elmi[1] = elm->n2;
    elmi[2] = elm->n3;
    elmi[3] = 2;
    GiD_fWriteElementMat(fdm, elm->id, elmi);
  }
  GiD_fEndElements(fdm);
  GiD_fEndMesh(fdm);

  GiD_fEndMeshGroup(fdm);


  /* write mesh for second time step */
  GiD_fBeginMeshGroup(fdm, "Mesh 2");

  GiD_fBeginMeshColor(fdm, "TestMsh", GiD_2D, GiD_Quadrilateral, 9, 0, 0.99, 0);
  /* coordinates */
  GiD_fBeginCoordinates(fdm);
  for ( i = 0; i < 9; i++ ) {
    node = nodes + i;
    GiD_fWriteCoordinates(fdm, node->id, node->x, node->y, node->z );
  }
  GiD_fEndCoordinates(fdm);
  /* elements */
  GiD_fBeginElements(fdm);

    elmi2[0] = 1;
    elmi2[1] = 7;
    elmi2[2] = 9;
    elmi2[3] = 3;
    elmi2[4] = 4;
    elmi2[5] = 8;
    elmi2[6] = 6;
    elmi2[7] = 2;
    elmi2[8] = 5;
    elmi2[9] = 2;
    GiD_fWriteElementMat(fdm, 1, elmi2);

  GiD_fEndElements(fdm);
  GiD_fEndMesh(fdm);

  GiD_fEndMeshGroup(fdm);





  /* now results for first time step */
  GiD_fBeginOnMeshGroup(fdr, "Mesh 1");

  GiD_fBeginResult(fdr, "EscalarNodos", "Analysis", 1.0, GiD_Scalar, GiD_OnNodes, NULL, NULL, 0, NULL);
  for ( i = 0; i < 9; i++ ) {
    GiD_fWriteScalar(fdr, nodes[i].id, Random());
  }
  GiD_fEndResult(fdr);

  GiD_fEndOnMeshGroup(fdr);



  /* now results for second time step */
  GiD_fBeginOnMeshGroup(fdr, "Mesh 2");

  GiD_fBeginResult(fdr, "EscalarNodos", "Analysis", 2.0, GiD_Scalar, GiD_OnNodes, NULL, NULL, 0, NULL);
  for ( i = 0; i < 9; i++ ) {
    GiD_fWriteScalar(fdr, nodes[i].id, Random());
  }
  GiD_fEndResult(fdr);

  GiD_fEndOnMeshGroup(fdr);


  // Close file(s)
#ifdef ASCII_FORMAT
  GiD_fClosePostMeshFile(fdm);
#endif
  GiD_fClosePostResultFile(fdr);

  GiD_PostDone();

  printf("Finished normally!!");
  return 0;
}

This also runs for ASCII and binary output, but I can only open the ASCII output in GiD. The msh- and res-files also look like expected.

When I open the binary file with GiD 12.0 the geometry is shown, and in the message lines it says "Results read (binary format).", but in the menu "View results" it say "Please load a MODEL first" everywhere.

Regards
Malte
User avatar
ronda
Posts: 8
Joined: Mon Oct 13, 2014 9:29 am

Re: GiDpost

Post by ronda »

Hello Malte, the bug with the mesh group in binary format is due to a constraint in GiD: "the results on mesh groups should come just after the mesh group definition". Attached you can find a working version of your sample code.
Attachments
BugMeshGroup02.c.zip
(1.22 KiB) Downloaded 383 times
mvscheven
Posts: 16
Joined: Thu Dec 04, 2014 4:26 pm
Location: Stuttgart, Germany

Re: GiDpost

Post by mvscheven »

Hi,

of course, you are right! In our code we do it in this order. Just in the test case I duplicated the blocks in the wrong order. Sorry for that!

I can confirm that your latest version of GiDpost works for me with groups for ASCII and binary output.

Thanks a lot for your help and the bug fix.

Regards
Malte
Post Reply