Exemple #1
0
// xxx TBD handle whitespace including CR/LF
// Takes a string in the form of an C/C++ enum content such as "{NONE, RED=2, GREEN}"
// and returns a vector of name/value (Eg NONE/0, RED/2, GREEN/3).
// If any errors are found in the string false is returned and the vector is empty.
bool get_enum(LPCTSTR pp, std::vector<enum_entry> &retval)
{
	retval.clear();

	// Make sure the enum string starts with the flag character {
	if (pp[0] != '{') return false;

	// Get rid of the trailing } so we just have the enum strings
	const char *pend = strchr(pp, '}');
	if (pend == NULL) return false;

	CString ss(pp+1, pend-pp-1);

	__int64 enum_val = 0;
	for (int ii = 0; ; ++ii)
	{
		CString entry;                  // One enum entry (comma separated)
		enum_entry ee;                  // Entry to add to the returned vector
		int eq_pos;                     // Posn of equals sign in the entry

		// Get a single enum entry and break from loop if no more
		if (!AfxExtractSubString(entry, ss, ii, ','))
			break;

		entry.TrimLeft();
		entry.TrimRight();
		if ((eq_pos = entry.Find('=')) == -1)
		{
			if (!valid_id(entry))
			{
				retval.clear();
				return false;
			}
			ee.name = entry;
		}
		else
		{
			// Get separate name and value
			ee.name = entry.Left(eq_pos);
			ee.name.TrimRight();
			if (!valid_id(ee.name))
			{
				retval.clear();
				return false;
			}
			enum_val = _atoi64(entry.Mid(eq_pos + 1));
		}

		ee.value = enum_val;
		retval.push_back(ee);
		//TRACE2("ENUM: %s=%ld\n", ee.name, long(enum_val));

		++enum_val;
	}

	return true;
}
Exemple #2
0
void diffuse()
{
  edge_id e_id;
  facet_id f_id;
  facetedge_id fe_id;
  body_id b_id,bb_id;
  REAL pressure;
  REAL mass;
  REAL coeff;

  if ( web.representation == STRING )
  { edge_diffusion_attr = find_attribute(EDGE,DIFFUSE_EATTR_NAME);
    FOR_ALL_EDGES(e_id)
    { fe_id = get_edge_fe(e_id);
      if ( !valid_id(fe_id) ) return;
      b_id = get_facet_body(get_fe_facet(fe_id));
      if ( !valid_id(b_id) ) invert(fe_id);
      b_id = get_facet_body(get_fe_facet(fe_id));
      if ( !valid_id(b_id) ) continue;
      pressure = get_body_pressure(b_id);
       
      if ( !equal_id(fe_id,get_next_facet(fe_id)) )
      { fe_id = get_next_facet(fe_id);
        bb_id = get_facet_body(get_fe_facet(fe_id));
        if ( !valid_id(bb_id) ) invert(fe_id);
        bb_id = get_facet_body(get_fe_facet(fe_id));
        pressure -= get_body_pressure(bb_id);
      }
      else bb_id = NULLBODY;
      if ( edge_diffusion_attr >= 0 )
         coeff = *(REAL*)get_extra(e_id,edge_diffusion_attr);
      else coeff = web.diffusion_const; 
      mass = web.scale*coeff*pressure*get_edge_length(e_id);
      set_body_fixvol(b_id,get_body_fixvol(b_id)-mass);
      if ( valid_id(bb_id) )
        set_body_fixvol(bb_id,get_body_fixvol(bb_id)+mass);
    }
  } /* end STRING */
bool CDFFDUseStruct::check_data()
{
	// Get values from the controls and validate them
	UpdateData();

	// Make sure name is given unless the container is a FOR (whence sub-elements are accessed via array index)
	if (name_.IsEmpty() && parent_type_ != CHexEditDoc::DF_FORV && parent_type_ != CHexEditDoc::DF_FORF)
	{
		TaskMessageBox("No Name", "Please enter a name for this element");
		ctl_name_.SetFocus();
		return false;
	}

	if (!name_.IsEmpty() && !valid_id(name_))
	{
		TaskMessageBox("Invalid STRUCT Name", "Please use alphanumeric characters (or "
						"underscores) and begin the name with an alphabetic character.");
		ctl_name_.SetFocus();
		return false;
	}
	if (name_.CompareNoCase("true") == 0 ||
		name_.CompareNoCase("false") == 0 ||
		name_.CompareNoCase("end") == 0 ||
		expr_eval::func_token(name_) != expr_eval::TOK_NONE)
	{
		TaskMessageBox("Reserved Name", name_ + " is reserved for internal use. Please choose another name.");
		ctl_name_.SetFocus();
		return false;
	}

	if (struct_.IsEmpty())
	{
		TaskMessageBox("No Defined Struct", "Please select a defined struct for this element");
		ctl_struct_.SetFocus();
		return false;
	}
	else if (!valid_id(struct_))
	{
		TaskMessageBox("Invalid Defined Struct Name", "Please use alphanumeric characters "
					  "(or underscore) and start with a alphabetic character.");
		ctl_name_.SetFocus();
		return false;
	}

	// We can only have an empty name if parent is FOR in which case there are no siblings
	ASSERT(!name_.IsEmpty() || pelt_->GetParent().GetNumChildren() == 1);

	// Check that the name is not the same as any siblings
	CXmlTree::CElt ee;

	// First find the actual element whose siblings we want to check (an IF takes the name of its child)
	for (ee = *pelt_; ee.GetParent().GetName() == "if" || ee.GetParent().GetName() == "jump"; ee = ee.GetParent())
		; // empty loop body

	// Check that older siblings don't have the same name
	for (ee--; !ee.IsEmpty(); ee--)
	{
		CXmlTree::CElt ee2;
		for (ee2 = ee; !ee2.IsEmpty() && (ee2.GetName() == "if" || ee2.GetName() == "jump"); ee2 = ee2.GetFirstChild())
			; // nothing here
		if (!ee2.IsEmpty() && ee2.GetAttr("name") == name_)
		{
			TaskMessageBox("Name in use", name_ + " has a sibling with the same name.\n\n"
				           "It is not be possible to differentiate between two elements "
			               "with the same name at the same level (eg, in expressions).");
			ctl_name_.SetFocus();
			return false;
		}
	}

	for (ee = *pelt_; ee.GetParent().GetName() == "if" || ee.GetParent().GetName() == "jump"; ee = ee.GetParent())
		; // empty loop body

	// Check that younger siblings don't have the same name
	for (++ee; !ee.IsEmpty(); ++ee)
	{
		CXmlTree::CElt ee2;
		for (ee2 = ee; !ee2.IsEmpty() && (ee2.GetName() == "if" || ee2.GetName() == "jump"); ee2 = ee2.GetFirstChild())
			; // nothing here
		if (!ee2.IsEmpty() && ee2.GetAttr("name") == name_)
		{
			TaskMessageBox("Name in use", name_ + " has a sibling with the same name.\n\n"
				           "It is not be possible to differentiate between two elements "
			               "with the same name at the same level (eg, in expressions).");
			ctl_name_.SetFocus();
			return false;
		}
	}

	return true;
}
Exemple #4
0
int list_check()
{
  int type;
  element_id id;
  int numerr = 0;


  /* free_discards(DISCARDS_ALL); */
  for ( type = 0 ; type < NUMELEMENTS ; type++ )
  { 
    element_id backid = NULLID;

    if ( (web.representation == SIMPLEX)  && (type == EDGE) ) continue;
    #ifndef HASH_ID
    /* check free list */
    {  int freecount,maxfree;
     maxfree = web.skel[type].maxcount - web.skel[type].count
                 - web.skel[type].discard_count;
    id = web.skel[type].free;
    freecount = 0;
    while ( id != NULLID )
    { freecount++;
      if ( freecount > maxfree )
      { sprintf(msg,"Type %d freelist has too many elements: %d.\n",
            type,freecount);
        erroutstring(msg);
        if ( ++numerr > MAXERR )
        {erroutstring("Too many errors.\n"); return numerr;}
        break;
      }
      if ( id_type(id) != type )
      { sprintf(msg,"Type %d freelist has bad id %lX\n",type,(unsigned long)id);
        erroutstring(msg);
        if ( ++numerr > MAXERR )
        {erroutstring("Too many errors.\n"); return numerr;}
        break;
      }
      if ( elptr(id)->backchain != backid )
      { sprintf(msg,
         "Type %d freelist has bad backchain %X instead of %X for id %lX\n",
            type, (unsigned long)elptr(id)->backchain,(unsigned long)backid,
           (unsigned long)id);
        erroutstring(msg);
        if ( ++numerr > MAXERR )
        {erroutstring("Too many errors.\n"); return numerr;}
      }
      backid = id;
       
      id = elptr(id)->forechain;
    } /* end while */
    if ( backid != web.skel[type].freelast )
    { sprintf(msg,"Type %d freelist has bad freelast %lX instead of %lX.\n",
          type, (unsigned long)web.skel[type].freelast,(unsigned long)backid);
      erroutstring(msg);
    }

    if ( freecount != maxfree )
    { sprintf(msg,"Type %d freelist has %d elements instead of %d.\n",
          type,freecount,maxfree);
      erroutstring(msg);
    }
    if ( !equal_id(id,NULLID) )
    { sprintf(msg,"Type %d freelist last id is non-null: %lX\n",type,
          (unsigned long)id);
      erroutstring(msg);
    }
    }
    #endif
    
#ifndef MPI_EVOLVER
  { int usedcount,maxused,discards;
    element_id prev_id;

    /* check used list */
    maxused = web.skel[type].count;
    id = web.skel[type].used;
    prev_id = NULLID;
    usedcount = 0;
    discards = 0;
    while ( valid_id(id) )
    { 
      if ( valid_element(id) )
        usedcount++;
      else discards++;

      if ( usedcount > maxused )
      { sprintf(msg,"Type %d usedlist has too many elements: %d.\n",
            type,usedcount);
        erroutstring(msg);
        if ( ++numerr > MAXERR )
        {erroutstring("Too many errors.\n"); return numerr;}
        break;
      }
      if ( id_type(id) != type )
      { sprintf(msg,"Type %d usedlist has bad id %lX of type %d\n",
            type,(unsigned long)id,id_type(id));
        erroutstring(msg);
        if ( ++numerr > MAXERR )
        { erroutstring("Too many errors.\n"); return numerr;}
        break;
      }
      if ( !equal_id(prev_id,elptr(id)->backchain) )
      { sprintf(msg,"Type %d used list id %lX has backchain %lX instead of %lX\n",
              type,(unsigned long)id,(unsigned long)elptr(id)->backchain,
             (unsigned long)prev_id);
        erroutstring(msg);
        if ( ++numerr > MAXERR )
        {erroutstring("Too many errors.\n"); return numerr;}
      }
      prev_id = id;
      id = elptr(id)->forechain;
    } /* end while */
    if ( usedcount != maxused )
    { sprintf(msg,"Type %d usedlist has %d elements.\n",type,usedcount);
      erroutstring(msg);
    }
    if ( discards != web.skel[type].discard_count )
    { sprintf(msg,"Type %d usedlist has %d elements.\n",type,usedcount);
      erroutstring(msg);
    }
    if ( !equal_id(id,NULLID) )
    { sprintf(msg,"Type %d usedlist last id is non-null: %lX\n",type,
          (unsigned long)id);
      erroutstring(msg);
    }
  }
#endif
  } /* end for loop */

  #ifdef MPI_EVOLVER
  for ( type = VERTEX ; type < NUMELEMENTS ; type++ )
  { int k;
    for ( k = 0 ; k < web.skel[type].maxcount ; k++ )
      if ( (web.skel[type].ibase[k]->local_id & OFFSETMASK) != k )
      { sprintf(msg,"Task %d: local_id is %08X on %s ibase[0x%X], self id %08X\n",
          this_task,(int)(web.skel[type].ibase[k]->local_id),
           typenames[type],k, (int)(web.skel[type].ibase[k]->self_id));
        erroutstring(msg);
      }
  }
  #endif
  
  return numerr;
} /* end list_check() */
Exemple #5
0
void torvol()
{
  facet_id f_id;    /* main facet iterator */
  body_id b_id;
  body_id b0_id,b1_id;    /* facet adjacent bodies */

#ifdef NEWTORVOL
struct qinfo f_info; /* for calling q_facet_torus_volume */
q_info_init(&f_info,METHOD_VALUE);
#endif

  /* adjust body volumes to the invariant constant for each */
  FOR_ALL_BODIES(b_id)
    set_body_volume(b_id,get_body_volconst(b_id),NOSETSTAMP);
  if ( web.representation == STRING )
    FOR_ALL_FACETS(f_id)
      set_facet_area(f_id,0.0);

  FOR_ALL_FACETS(f_id)
  {
    REAL t;     /* accumulator for this facet */

    if ( get_fattr(f_id) & NONCONTENT ) continue;

    /* find adjacent bodies */
    b0_id = get_facet_body(f_id);
    b1_id = get_facet_body(facet_inverse(f_id));
    if ( !valid_id(b0_id) && !valid_id(b1_id) ) continue;

#ifdef NEWTORVOL
    f_info.id = f_id;
    q_facet_setup(NULL,&f_info,NEED_SIDE|TORUS_MODULO_MUNGE|ORIENTABLE_METHOD);
    t = q_facet_torus_volume(&f_info);
    if ( valid_id(b0_id) )
        add_body_volume(b0_id,t);
    if ( valid_id(b1_id) )
        add_body_volume(b1_id,-t);
#else
    REAL *v[FACET_VERTS];  /* pointers to three vertex coordinates */
    facetedge_id fe;
    int i;
    REAL adj[FACET_EDGES][MAXCOORD];  /* torus wrap adjustments for edge */
    /* get basic info */
    fe = get_facet_fe(f_id);
    for ( i = 0 ; i < FACET_EDGES ; i ++ )
    {
      v[i] = get_coord(get_fe_tailv(fe));
      get_edge_adjust(get_fe_edge(fe),adj[i]); 
      fe = get_next_edge(fe);
    }

    /* basic tetrahedron */
    t = triple_prod(v[0],v[1],v[2]);

    /* torus wrap corrections */
    for ( i = 0 ; i < FACET_EDGES ; i++ )
    {
      /* two-vertex term */
      t += triple_prod(adj[(i+1)%FACET_EDGES],v[i],v[(i+1)%FACET_EDGES])/2;
      t -= triple_prod(adj[(i+2)%FACET_EDGES],v[i],v[(i+1)%FACET_EDGES])/2;

      /* one-vertex term */
      t += triple_prod(v[i],adj[(i+2)%FACET_EDGES],adj[i]);
    }

    if ( valid_id(b0_id) )
       add_body_volume(b0_id,t/6);
    if ( valid_id(b1_id) )
       add_body_volume(b1_id,-t/6);
#endif
        }
#ifdef NEWTORVOL
q_info_free(&f_info);
#endif
}