Esempio n. 1
0
//=============================================================================
static void
InitializeMeshStructure(
Parmesh_t* ParMesh )  ///< particle mesh structure
{
  ParMesh->ElemFull = (int*) realloc( ParMesh->ElemFull, 1 * sizeof(int) );
  assert_error( ParMesh->ElemFull != NULL, "Memory allocation error");
  ParMesh->ElemFull[0] = 0;
    
  ParMesh->ElemPartly= (int*) realloc( ParMesh->ElemPartly, 1 * sizeof(int) );
  assert_error( ParMesh->ElemPartly != NULL, "Memory allocation error");
  ParMesh->ElemPartly[0] = 0;

  ParMesh->points[0][0] = 0.;
  
  for ( int dir = 1 ; dir <= 3 ; dir++ )
  {
    ParMesh->points[dir] = (double*)
      realloc(ParMesh->points[dir],1*sizeof(double));
    assert_error( ParMesh->points[dir] != NULL, "Memory allocation error");
  }
  
  ParMesh->ConTab[0][0] = 0;

  for ( int i = 1 ; i <= 10 ; i++ )
  {
    ParMesh->ConTab[ i ] = (int*)
      realloc( ParMesh->ConTab[ i ], 1*sizeof(int) );
    assert_error( ParMesh->ConTab[ i ] != NULL, "Memory allocation error");
  }
}
Esempio n. 2
0
bool ScriptedEngine::validate_script(const string& script, bool viz) {
#ifndef _DEBUG
  error("not implemented in Release mode");
  return false;
#else
  vector<string> lines = split(lower(script), "\n");
  lines.push_back("finished:"); // last state
  enum Step {
    None,
    Setup,
    Action,
    Result,
  };
  enum SubStep {
    SubNone = 0,
    SubHeroes = 1,
    SubDecks = 2,
    SubBoard = 4,
  }; 
  Step step = None;
  SubStep substep = SubNone;
  PPlayer player1, player2;
  PHero hero1, hero2;
  Deck deck1, deck2;

  int num;  // current line number
  auto read_player = [this, &num](ListString& line) {
    assert_error(board.player1 && board.player2, "players are not yet defined!");
    string p = pop_at(line, 0);
    if (p == "p1")
      return CAST(board.players[0], ScriptedPlayer);
    elif(p == "p2")
      return CAST(board.players[1], ScriptedPlayer);
    else
Esempio n. 3
0
static void
test_type_hint_parse(void)
{
  TypeHint t;
  GError *e = NULL;

  testcase_begin("Testing type hint parsing");

  assert_type_hint(NULL, TYPE_HINT_STRING);
  assert_type_hint("string", TYPE_HINT_STRING);
  assert_type_hint("literal", TYPE_HINT_LITERAL);
  assert_type_hint("boolean", TYPE_HINT_BOOLEAN);
  assert_type_hint("int", TYPE_HINT_INT32);
  assert_type_hint("int32", TYPE_HINT_INT32);
  assert_type_hint("int64", TYPE_HINT_INT64);
  assert_type_hint("datetime", TYPE_HINT_DATETIME);
  assert_type_hint("default", TYPE_HINT_DEFAULT);

  assert_false(type_hint_parse("invalid-hint", &t, &e),
               "Parsing an invalid hint results in an error.");

  assert_error(e, TYPE_HINTING_INVALID_TYPE, "invalid-hint");

  testcase_end();
}
Esempio n. 4
0
//=============================================================================
char*
ListFilesInDirectory(
const char* DirName ) ///< name of a directory
{
  if ( DirName == NULL ) return NULL;
    
  DIR *directory = opendir(DirName);
  
  if ( directory == NULL ) return NULL;
  
  // entry in the directory
  struct dirent *entry;
  
  // initialize file list to empty
  char* FileList = StringDuplicate("");

  // loop over entries
  while( (entry = readdir(directory)) != NULL )
  {
    // filter . and .. entries
    if ( StringCompare(entry->d_name,".") || 
         StringCompare(entry->d_name,"..") ) continue;
    
    // append file name and separator to list
    StringAppend(&FileList,entry->d_name);
    StringAppend(&FileList," ");
  }
  
  // close directory
  assert_error( closedir(directory) == 0, "Failed to close directory");
  
  return FileList;
}
Esempio n. 5
0
void init()
{
    static bool inited = false;
    if (inited) return;
    inited = true;

    string path;
#ifndef TARGET_WIN32
    path = ofFilePath::getCurrentExeDir() + "/Drivers"; // osx / linux
#else
    path = ofFilePath::getCurrentExeDir() + "/OpenNI2/Drivers"; // windows
#endif
    if (ofFile::doesFileExist(path, false))
    {
#ifndef TARGET_WIN32
        setenv("OPENNI2_DRIVERS_PATH", path.c_str(), 1);
#endif
        assert_error(openni::OpenNI::initialize());
    }
    else
    {
        ofLogError("ofxNI2") << "libs not found";
        ofExit(-1);
    }
}
Esempio n. 6
0
void
ShaderAPITest::test_uniform_neg_location(void)
{
	GLuint program;
	GLfloat data[4];

	program = make_program("#version 110\nvoid main() { gl_Position = vec4(1.0, 1.0, 1.0, 1.0); }\n", NULL);
	assert_no_error();
	glUniform1i_func(-1, 1);
	assert_no_error();
	glUniform1i_func(-200, 1);
	assert_error(GL_INVALID_OPERATION);
	glUniformMatrix2fv_func(-1, 1, GL_FALSE, data);
	assert_no_error();
	glUniformMatrix2fv_func(-200, 1, GL_FALSE, data);
	assert_error(GL_INVALID_OPERATION);
}
Esempio n. 7
0
inline float read_float(const int num, const KwArgs& args, const string& key, float defaut) {
  auto it = args.find(key);
  if (it == args.end()) return defaut;
  try{ return convert_str_to<float>(it->second); }
  catch (const char* msg) {
    assert_error(false, "could not convert arg %s='%s' to float (reason: %s)",
      key.c_str(), it->second.c_str(), msg);
  }
  return -1.f;
};
Esempio n. 8
0
void barf(const char *fmt, ...) {
  char msg[2048];
  va_list args;

  va_start(args, fmt);
  vsnprintf(msg, 2048, fmt, args);
  va_end(args);

  throw assert_error(msg);
}
Esempio n. 9
0
END_TEST

START_TEST (numbers_will_be_ignored_while_learning)
{
    int rc;
    strbuf *string;

    rc = varnam_learn (varnam_instance, "01");
    assert_error (rc);
    string = strbuf_init (50);
    strbuf_add (string, "Can't process '0'. One or more characters in '01' are not known");
    ck_assert_str_eq (varnam_get_last_error (varnam_instance), strbuf_to_s (string));

    rc = varnam_learn (varnam_instance, "१०१");
    assert_error (rc);
    strbuf_clear (string);
    strbuf_add (string, "Nothing to learn from '१०१'");
    ck_assert_str_eq (varnam_get_last_error (varnam_instance), strbuf_to_s (string));
    strbuf_destroy (string);
}
Esempio n. 10
0
//=============================================================================
static void
SortElements(
int*  elemT,
int*  elemP,
int** ElemFullPtr,
int** ElemPartlyPtr )
{
  int elemCount = 0; // Counter for number of new elements

  // Get the original elements from elemT and elemP and distribute
  for ( int iElem = 1 ; iElem <= elemT[ 0 ] ; iElem++ )
  {
    // Check whether it is fully or partly inside
    if ( elemP[ iElem ] == PRE_NODES_PER_EL )
    {
      // Element is fully inside, register in ElemFull
      elemCount = ++(*ElemFullPtr)[ 0 ];

      if ( ( elemCount % MBLOCK ) == 1 )
      {
        *ElemFullPtr = (int*) realloc( (*ElemFullPtr), ( elemCount + MBLOCK ) * sizeof(int) );
         assert_error( *ElemFullPtr != NULL, "Memory allocation error");
      }
      
      (*ElemFullPtr)[ elemCount ] = elemT[ iElem ];
    }
    else
    {
      // Element partly inside, register in ElemPartly
      elemCount = ++(*ElemPartlyPtr)[ 0 ];

      if ( ( elemCount % MBLOCK ) == 1 )
      {
       (*ElemPartlyPtr) = (int*) realloc( (*ElemPartlyPtr), ( elemCount + MBLOCK ) * sizeof(int) );
       assert_error( *ElemPartlyPtr != NULL, "Memory allocation error");
      }
           
      (*ElemPartlyPtr)[ elemCount ] = elemT[ iElem ];
    }
  }
}
Esempio n. 11
0
END_TEST

START_TEST (initialize_using_invalid_lang_code)
{
  int rc;
  char *errMsg = NULL;
  varnam *handle;
  rc = varnam_init_from_id ("mll", &handle, &errMsg);
  assert_error (rc);
  ck_assert (errMsg != NULL);
  varnam_destroy (handle);
}
Esempio n. 12
0
//=============================================================================
/// Find nodes of inner domain that are outside outer domain.
//=============================================================================
static void
FindNodesOutside(
const particle_t  particle[], ///< particle structure
const mesh_t*     mesh_o,     ///< outer domain mesh
      mesh_t*     mesh )      ///< mesh
{
  int OutsideNodesNb = 0;
  
  for ( int node = 1 ; node <= mesh->NbOfNodes ; node++ )
  {
    const double
    *point = mesh->points[node],
    *position = particle[1].Pos,
    NodeCoord[4] = {0., position[1]+point[1], position[2]+point[2],
                    position[3]+point[3]}; // node coordinates in mesh_o frame
    
    int temp = 0, // temp variable used for SearchElemContainingPoint
    // search an element of the outer domain that contains this node
    ElemContainer = SearchElemContainingPoint(
    mesh_o, true, NodeCoord, &temp, &temp );
    
    // if the node isn t outside, just continue
    if ( ElemContainer != 0 )
    {
      mesh->OutsideNodes[node] = false;
      continue;
    }
    
    // update outside nodes count
    OutsideNodesNb++;
    
    // add node to list
    mesh->OutsideNodes[node] = true;
  }
  
  // statistics
  StatAdd("Nodes outside outer domain", OutsideNodesNb);
  
  debug("\n\t"INT_FMT" nodes outside outer domain\n", OutsideNodesNb);
  
  // if there are nodes outside, then check the particles are fully inside, otherwise stop simulation
  if ( OutsideNodesNb == 0 ) return;
  
  for ( int iPar = 1 ; iPar <= particle[1].ParNb ; iPar++ )
  for ( int i = 1 ; i <= particle[iPar].mesh->NodesIn[0] ; i++ )
  {
    int node = particle[iPar].mesh->NodesIn[i];
    assert_error( mesh->OutsideNodes[node] == false,
                 "Particle "INT_FMT" touched a boundary at node "INT_FMT"\n",
                 iPar,node);
  }
}
Esempio n. 13
0
void
ShaderAPITest::test_uniform_scalar_count(void)
{
	GLuint program;
	GLint location;
	GLfloat data[128];

	program = make_program("#version 110\nuniform vec2 x;\nvoid main() { gl_Position.xy = x; }\n", NULL);
	location = glGetUniformLocation(program, "x");
	assert_no_error();
	glUniform2fv(location, 64, data);
	assert_error(GL_INVALID_OPERATION);
}
Esempio n. 14
0
QString separateGroups(cqstring s, int groupSize, QChar separator) {
	assert_error(groupSize > 0, "groupSize: %d", groupSize);
	int groupCount = (s.length() - 1) / groupSize + 1;
	int len = s.length() + groupCount - 1;
	QString grouped(len, separator);

	int j = 0;
	for (int i = 0; i < s.length(); i++) {
		grouped[j++] = s[i];
		if ((j + 1) % (groupSize + 1) == 0) j++;
	}

	return grouped;
}
Esempio n. 15
0
//==============================================================================
char*
StringDuplicate(
const char *string )  ///< string to be duplicated
{
  if ( string == NULL ) return NULL;

  char *newstring = (char*) calloc( strlen(string) + 1, sizeof(char) );

  assert_error( newstring != NULL, "Memory allocation error");
  
  strcpy(newstring, string);
  
  return newstring;
}
Esempio n. 16
0
END_TEST

START_TEST (words_with_repeating_characters_will_not_be_learned)
{
    int rc;
    strbuf *string;
    const char *word_to_learn = "കകകകകകക";

    rc = varnam_learn (varnam_instance, word_to_learn);
    assert_error (rc);
    string = strbuf_init (50);
    strbuf_addf (string, "'%s' looks incorrect. Not learning anything", word_to_learn);
    ck_assert_str_eq (varnam_get_last_error (varnam_instance), strbuf_to_s (string));
    strbuf_destroy (string);
}
Esempio n. 17
0
//==============================================================================
void
StringAppend(
      char**  string1,  ///< initial string
const char*   string2 ) ///< string to be appended
{
  // do nothing and return if there is no string to append
  if ( string2 == NULL || strlen(string2) == 0 ) return;
  
  *string1 = (char*) realloc( *string1,
    (strlen(*string1) + strlen(string2) + 1)*sizeof(char) );
  
  assert_error( *string1 != NULL, "Memory allocation error");
  
  strcat(*string1, string2);
}
Esempio n. 18
0
void
ParElemNodeTouch(
const mesh_t*       mesh,
const particle_t*   particle,
const int        element,
      int**      ElemTouchedPtr,
      int**      ElemTouchedNodeInPtr,
      int**      NodesIn )
{
  bool *NodeVisited = NULL, // nodes and
       *ElemVisited = NULL; // elements visited
  
  AllocVbool( mesh->NbOfNodes,NodeVisited );
  AllocVbool( mesh->NbOfElements,ElemVisited );

  for ( int i = 0 ; i <= mesh->NbOfElements ; i++ )
    ElemVisited[i] = false;
    
  for ( int i = 0 ; i <= mesh->NbOfNodes ; i++ )
    NodeVisited[i] = false;

  (*NodesIn) = (int*) realloc( (*NodesIn), sizeof(int) );
  
  assert_error( (*NodesIn) != NULL, "Memory allocation error");

  (*NodesIn)[ 0 ] = 0; // Number of nodes inside particle

  ParElemNodeTouchWrapped(
    mesh, particle, element, ElemTouchedPtr, ElemTouchedNodeInPtr,
    NodesIn, NodeVisited, ElemVisited );

  debug( "\t" INT_FMT " nodes inside\n", (*NodesIn)[ 0 ] );

  free(ElemVisited);
  free(NodeVisited);
}
Esempio n. 19
0
//=============================================================================
void
GetParticleMesh(
const mesh_t*     mesh,
      particle_t  particle[] )
{
  if ( particle == NULL ) return;
  
  debug( "\nParticles : meshing\n");
  
  // Elements touched by the particles
  int *ElemTouched = NULL,
         *ElemTouchedNodesIn = NULL,
         // store the surface nodes inside particle domain
         *NodesConnectedToOutside = NULL,
         // store the surface innode-outnode connectivity
         ***InOutSurfConTab = NULL;
  
  AllocVint( NODELMT, NodesConnectedToOutside );
  
  InOutSurfConTab = (int***) calloc( mesh->NbOfNodes + 1, sizeof(int**) );
  assert_error( InOutSurfConTab != NULL, "Memory allocation error");
  
  for ( int node = 1 ; node <= mesh->NbOfNodes ; node++ )
  {
    InOutSurfConTab[ node ] = (int**) calloc( 3, sizeof(int*) );
    assert_error( InOutSurfConTab[ node ] != NULL, "Memory allocation error");
    
    for ( int i = 0 ; i <= 2 ; i++ )
      AllocVint(0,InOutSurfConTab[ node ][ i ]);
  }

  // fill in the ParMesh structure
  for ( int iPar = 1 ; iPar <= particle[1].ParNb ; iPar++ )
  {
    // pointer to particle mesh
    Parmesh_t *ParMesh = particle[iPar].mesh;
    
    // Initialization
    InitializeMeshStructure( ParMesh );

    // Number of surface nodes in particle domain
    NodesConnectedToOutside[ 0 ] = 0;
  
    ElemTouched = (int*) realloc( ElemTouched, sizeof(int) );
    ElemTouched[ 0 ] = 0; // Number of element touched
    
    ElemTouchedNodesIn = (int*) realloc( ElemTouchedNodesIn, sizeof(int) );
    ElemTouchedNodesIn[ 0 ] = 0; // Number of element partly inside

    // Find the element which contains the center of mass of the particle
    int temp = 0, // for unused variables

    ElemMassCenter = SearchElemContainingPoint(
                      mesh, true, particle[iPar].Pos0, &temp, &temp);

    // Find the elements and nodes inside the current particle
    ParElemNodeTouch(
      mesh, &particle[ iPar ], ElemMassCenter,
      &ElemTouched, &ElemTouchedNodesIn, &(ParMesh->NodesIn) );

    // Distributes elements touched into elements fully and partly inside
    SortElements(
      ElemTouched, ElemTouchedNodesIn,
      &(ParMesh->ElemFull), &(ParMesh->ElemPartly) );

    debug( "\t" INT_FMT " elements fully inside" "\n",
          ParMesh->ElemFull[ 0 ] );
    debug( "\t" INT_FMT " elements partly inside" "\n",
          ParMesh->ElemPartly[ 0 ] );

    // Find the node-node connections cut
    // find edge node and fill InOutSurfConTab structure
    FillInOutSurfConTab(
      mesh, &particle[ iPar ],
      ParMesh->ElemPartly, ParMesh->points,
      InOutSurfConTab, NodesConnectedToOutside );
    
    // Surface elements are processed on the basis of InOutSurfConTab
    // and added to ElemFull
    ParConnGeo(
      mesh, &particle[ iPar ], ParMesh->points, ParMesh->ConTab,
      &(ParMesh->ElemFull), ParMesh->ElemPartly,
      InOutSurfConTab, NodesConnectedToOutside );
    
    debug( "\t" INT_FMT " nodes on surface\n",
          NodesConnectedToOutside[ 0 ] );
    debug( "\t" INT_FMT " nodes created\n",
          (int) ParMesh->points[ 0 ][ 0 ] );
    debug( "\t" INT_FMT " elements inside after sub-meshing\n",
          ParMesh->ElemFull[ 0 ] );
    
    // write particle mesh to file
//    WriteParMeshVTK( iPar, mesh, ParMesh );

    // statistics
    StatAdd("Particle meshing : elements fully inside",
            ParMesh->ElemFull[ 0 ]);
  }
  
  free(ElemTouched);
  free(ElemTouchedNodesIn);

  free(NodesConnectedToOutside);
  
  for ( int node = 1 ; node <= mesh->NbOfNodes ; node++ )
  {
    for ( int i = 0 ; i <= 2 ; i++ )
      free(InOutSurfConTab[ node ][i]);
    
    free(InOutSurfConTab[ node ]);
  }
  
  free(InOutSurfConTab);
}
Esempio n. 20
0
void strings_drop() {
  assert_error(strings_top > strings);
  do {
    strings_top--;
  } while(strings_top > strings && strings_top[-1]);
}
Esempio n. 21
0
/// Write velocity and pressure to a legacy vtk file
void
FluidWriteVTK(
const char*   FileName,       ///< file name
const bool    FormatIsBinary, ///< file format : ascii or FormatIsBinary
const bool    WritePre,       ///< save or not pressure field
const mesh_t* mesh,           ///< mesh structure
const double**  Vel,            ///< velocity field
const double*   Pre )           ///< pressure field
{  
  // check file name
  assert( ( FileName != NULL ) && ( strlen(FileName) > 0 ) );
  // check pointers
  assert( mesh != NULL );
  assert( Vel != NULL );
  assert( Pre != NULL );
  
  assert_error( FormatIsBinary == false,
           " Binary format does not work, probably needs big endian");

//=============================================================================

  // full name of the file
  char FullFileName[30] = "";
  
  // create full file name
  sprintf(FullFileName,"%s" ".vtk",FileName);
  
  // open file
  FILE* FileId = fopen( FullFileName, "w" );
  assert_error(FileId, "Failed to open %s", FullFileName);

//=============================================================================

  // Write header
  fprintf( FileId, "# vtk DataFile Version 3.0" "\n" );
  fprintf( FileId, "spaf fluid" "\n" );
  if ( FormatIsBinary ) fprintf( FileId, "BINARY" "\n" );
  else          fprintf( FileId, "ASCII" "\n" );
  fprintf( FileId, "DATASET UNSTRUCTURED_GRID" "\n" );
    
//=============================================================================

  // Write geometric table
  fprintf( FileId, "POINTS " INT_FMT " float" "\n", mesh->NbOfNodes);
  
  if ( FormatIsBinary )
    for ( int NodeId = 1 ; NodeId <= mesh->NbOfNodes ; NodeId++ )
    for ( int dir = 1 ; dir <= 3 ; dir++ )
      fwrite( (float*) &(mesh->points[NodeId][dir]), sizeof(float), 1, FileId );
  else
    for ( int NodeId = 1 ; NodeId <= mesh->NbOfNodes ; NodeId++ )
      fprintf( FileId, "%g %g %g" "\n",
               (float) mesh->points[ NodeId ][ 1 ],
               (float) mesh->points[ NodeId ][ 2 ],
               (float) mesh->points[ NodeId ][ 3 ] );
  
//=============================================================================

  // Write connectivity table with 0 offset numbered nodes (hence the "-1")
  fprintf( FileId, "\nCELLS " INT_FMT " " INT_FMT "\n",
           mesh->NbOfElements, 11*mesh->NbOfElements );
  
  if ( FormatIsBinary )
    for ( int ElemId = 1 ; ElemId <= mesh->NbOfElements ; ElemId++ )
    {
      // array containing the element connectivity in proper format for binary legacy vtk
      int ElemCon[11] = {10,0,0,0,0,0,0,0,0,0,0};
      for ( int node = 1 ; node <= 10 ; node++ )
        ElemCon[node] = (int) mesh->ConTab[ElemId][node]-1;
        
      // write element connectivity
      fwrite( ElemCon , sizeof(int) , 11 , FileId );
    }
  else
    for ( int ElemId = 1 ; ElemId <= mesh->NbOfElements ; ElemId++ )
    {
      fprintf( FileId, "10 " );

      for ( int LocalNode = 1 ; LocalNode <= 10 ; LocalNode++ )
        fprintf( FileId, "%d ", (int) mesh->ConTab[ ElemId ][ LocalNode ]-1 );

      fprintf( FileId, "\n" );
    }
  
  // Write cell types
  fprintf( FileId, "\nCELL_TYPES " INT_FMT "\n", mesh->NbOfElements );
  
  if ( FormatIsBinary )
  {
    int CellType = 24;
    
    for ( int ElemId = 1 ; ElemId <= mesh->NbOfElements ; ElemId++ )
      fwrite( &CellType , sizeof(int) , 1 , FileId );
  }
  else
    for ( int ElemId = 1 ; ElemId <= mesh->NbOfElements ; ElemId++ )
      fprintf( FileId, "24" "\n" );
  
//=============================================================================

  // Write data
  fprintf( FileId, "\nPOINT_DATA %d" "\n",mesh->NbOfNodes);

  // Write velocity field
  fprintf( FileId, "VECTORS velocity float" "\n");
  
  if ( FormatIsBinary )
    error("Binary not implemented");
  else
    for ( int NodeId = 1 ; NodeId <= mesh->NbOfNodes ; NodeId++ )
      fprintf( FileId, "%g %g %g" "\n",
               (float) Vel[ 1 ][ NodeId ],
               (float) Vel[ 2 ][ NodeId ],
               (float) Vel[ 3 ][ NodeId ] );
  
//=============================================================================
  
  // Write pressure field if required
  if ( WritePre == true )
  {
    // vector of pressure value over all nodes
    double *PreInterp = (double*) calloc(mesh->NbOfNodes+1,sizeof(double));
    
    for ( int iElem = 1; iElem <= mesh->NbOfElements; iElem++ )
    for ( int iintocal1 = 1; iintocal1 <= PRE_NODES_PER_EL; iintocal1++ )
    {
      // For pressure nodes, just get pressure from press vector
      int iNodeGlobal1 = mesh->ConTab[ iElem ][ iintocal1 ];
      PreInterp[ iNodeGlobal1 ] = Pre[ mesh->VelToPreNodeMap[ iNodeGlobal1 ] ];
      
      // For edges nodes, interpolate pressure from corner nodes
      for ( int iintocal2 = iintocal1 + 1; iintocal2 <= PRE_NODES_PER_EL; iintocal2++ )
      {
        int iNodeGlobal2    = mesh->ConTab[ iElem ][ iintocal2 ];
        int iNodeGlobalEdge = mesh->ConTab[ iElem ][ mesh->ConTabLocal[ iintocal1 ][ iintocal2 ] ];
        
        PreInterp[ iNodeGlobalEdge ] =
          .5 * ( PreInterp[ iNodeGlobal1 ] +
                 Pre[ mesh->VelToPreNodeMap[ iNodeGlobal2 ] ] );
      }
    }

    fprintf( FileId, "\nSCALARS pressure float 1" "\n");
    fprintf( FileId, "LOOKUP_TABLE default" "\n");

    // write pressure field  
    if ( FormatIsBinary )
      for ( int NodeId = 1 ; NodeId <= mesh->NbOfNodes ; NodeId++ )
        fwrite( (float*) &(PreInterp[NodeId]) , sizeof(float), 1 , FileId );
    else
      for ( int NodeId = 1 ; NodeId <= mesh->NbOfNodes ; NodeId++ )
        fprintf( FileId, "%g" "\n", (float) PreInterp[ NodeId ] );
  
    free(PreInterp);
  }

  fclose( FileId );
}
Esempio n. 22
0
/*--------------------------------------------------------------------
Purpose:
  Get the elements and nodes on the velocity mesh that are touched by the particle.
  The elements may be partly inside, but only nodes inside are registered

Input:
  d: data structure
  particle: the particle
  element: current element checked
  NodeVisited: node visited is marked in the list of all nodes
  ElemVisited: element visited is marked in list of all elements

Output:
  ElemTouched: list of elements touched by the particles,
  ElemTouchedNodeIn: list of elements partly/fully inside the particles,
  nodesIS: list of nodes touched by the particles

By: Veeramani
Update: 29/Sep/06 Antoine
--------------------------------------------------------------------*/
static void
ParElemNodeTouchWrapped(
const mesh_t*     mesh,
const particle_t* particle,
const int      element,
      int**    ElemTouchedPtr,
      int**    ElemTouchedNodeInPtr,
      int**    NodeInPtr,
      bool*       NodeVisited,
      bool*       ElemVisited )
{
  int node, theNode, iElem, nextEl,
        NodeInPar,
        count; // Temporary variable for keeping count

  ElemVisited[ element ] = true;
  
  // get the number of nodes of element in particle
  NodeInPar = ElemNodeNbInPar( mesh, particle, element );

  if ( NodeInPar )
  {
    // increment the number of elements touched
    count = ++(*ElemTouchedPtr)[ 0 ];
    
    // Reallocate only when count exceeds a multiple of memory block
    if ( ( count % MBLOCK ) == 1 )
    {
      *ElemTouchedPtr = (int*) realloc( (*ElemTouchedPtr), ( count + MBLOCK ) * sizeof(int) );
      assert_error( *ElemTouchedPtr != NULL, "Memory allocation error");
    }
    
    (*ElemTouchedPtr)[ count ] = element;

    count = ++(*ElemTouchedNodeInPtr)[ 0 ];
    
    // Reallocate only when count exceeds a multiple of memory block
    if ( ( count % MBLOCK ) == 1 )
    {
      *ElemTouchedNodeInPtr = (int*) realloc( (*ElemTouchedNodeInPtr), ( count + MBLOCK ) * sizeof(int) );
      assert_error( *ElemTouchedNodeInPtr != NULL, "Memory allocation error");
    }
    (*ElemTouchedNodeInPtr)[ count ] = NodeInPar;

    // check neighbouring elements recursively
    for ( node = 1 ; node <= NODES_PER_EL ; node++ )
    {
      theNode = mesh->ConTab[ element ][ node ];
      
      if ( NodeVisited[ theNode ] == false )
      {
        NodeVisited[ theNode ] = true;

        // Check whether node is inside the particle
        if ( IsNodeInPar( mesh, particle, theNode ) )
        {
          count = ++(*NodeInPtr)[ 0 ];
          
          // Reallocate only when count exceeds a multiple of memory block
          if ( ( count % MBLOCK ) == 1 )
          {
            *NodeInPtr = ( int * ) realloc( (*NodeInPtr), ( count + MBLOCK ) * sizeof(int) );
            assert_error( *NodeInPtr != NULL, "Memory allocation error");
          }
          
          (*NodeInPtr)[ count ] = theNode;
        }

        // check in inverse ConTab
        for ( iElem = 1 ; iElem <= NbOfEntriesInRow(mesh->InvConTab, theNode-1);  iElem++ )
        {
          nextEl = EntryNode(mesh->InvConTab, theNode-1, iElem-1);
          
          if ( ElemVisited[ nextEl ] == false )
            ParElemNodeTouchWrapped(
              mesh, particle, nextEl,
              ElemTouchedPtr, ElemTouchedNodeInPtr, NodeInPtr, NodeVisited, ElemVisited );
        }
      }
    }
  }
}