Ejemplo n.º 1
0
_Variable::_Variable (_String&s, bool isG)
{
    theName         = (_String*)checkPointer(new _String(s));
    varFlags        = HY_VARIABLE_NOTSET|(isG?HY_VARIABLE_GLOBAL:0);
    varValue        = nil;
    varFormula      = nil;
    SetBounds       (DEFAULTLOWERBOUND, DEFAULTUPPERBOUND);
    InsertVar       (this);
}
Ejemplo n.º 2
0
//__________________________________________________________________________________
void  ReplaceVar (_Variable* theV)
{
    long pos = variableNames.Find (theV->theName);
    if (pos>=0) {
        pos = variableNames.GetXtra(pos);
        UpdateChangingFlas   (pos);
        variablePtrs.Replace (pos,theV,true);
    } else {
        InsertVar (theV);
    }
}
Ejemplo n.º 3
0
static int
ProcessLine (statusfile_t *sf, char *section, char *line)
{
char tmp[BUFSIZE], *p, *q, *last;
hash_item_t    *h_var;

  h_var = irrd_malloc(sizeof(hash_item_t));

  tmp[BUFSIZE-1] = '\0';
  strncpy(tmp, line, BUFSIZE);

  if (VarTrim(tmp)) {
    /* Sanity check: no " before = */
    p = strchr(tmp, '"');
    q = strchr(tmp, '=');
    if (p && (p < q)) return (0);

    if ((p = strtok_r(tmp, "=", &last)) != NULL) {
      /* No " in the key */
      if ((q = strchr(p, '"')) != NULL) return (0);

      h_var->key = strdup(p);

      if ((p = strtok_r(NULL, "=", &last)) != NULL) {
	 /* The " must follow the = if any */
         if ((q = strchr(p, '"')) != NULL) {
	    if (q != p) return (0);
	    /* Truncate the string at the next " */
	    p = q + 1;
	    if ((q = strchr(p, '"')) != NULL) *q = '\0';
	    else return (0);
      }
    }

    h_var->value = strdup(p);

    return (InsertVar(sf, section, h_var));
    }
  }

  /* Failure cases */
  if (h_var->key) irrd_free(h_var->key);
  irrd_free(h_var);

  return (0);
}
Ejemplo n.º 4
0
_Variable::_Variable (_String&s, _String&f, bool isG)//:  _Formula (f)
{
    //hasBeenChanged = false;
    //isGlobal = isG;
    theName     = (_String*)checkPointer(new _String(s));
    varFlags    = isG?HY_VARIABLE_GLOBAL:0;
    varValue    = nil;
    SetBounds   (DEFAULTLOWERBOUND, DEFAULTUPPERBOUND);
    InsertVar   (this);
    varFormula = new _Formula (f);
    if (varFormula->IsAConstant()) {
        _PMathObj theP = varFormula->Compute();
        if (theP) {
            SetValue (theP);
            delete   (varFormula);
            varFormula = nil;
        } else {
            return;
        }
    }
}
Ejemplo n.º 5
0
int 
SetStatusString (statusfile_t *sf, char *section, char *variable, char *value)
{
hash_item_t *p_hi;
int ret = 0;

if (sf->filename == NULL) return (0);

if (!pthread_mutex_lock(&(sf->mutex_lock))) {
   /* Do we delete the value? */
   if (value == NULL) {
      DeleteVar(sf, section, variable);
      ret = 1;
      }
   /* See if its already in there.  If it is, then replace the current val */
   else if ((p_hi = LookupVar(sf, section, variable)) != NULL) {
      if ((p_hi->value != NULL) && strcmp(p_hi->value, value)) {
         free(p_hi->value);
	 p_hi->value = strdup(value);
	 }
      ret = 1;
      }
   /* If its not, add a new value */
   else {
      p_hi = irrd_malloc(sizeof(hash_item_t));
      p_hi->key = strdup(variable);
      p_hi->value = strdup(value);
      if (InsertVar(sf, section, p_hi)) ret = 1;
      }

   ret = WriteStatusFile(sf, NULL);

   pthread_mutex_unlock(&(sf->mutex_lock));
   }

return (ret);
}
Ejemplo n.º 6
0
void run_Zmatrices_calculation_scattered_field(Zmatrices& Z_matrices, UINT Lagrange_degree,
	MATRIX M, MATRIX J, GRID& rho, double material_param, const char* result_file)
{
	// Simulation parameters
	int N_T = Z_matrices.z_N_T;
	double dt = Z_matrices.z_dt;
	double c = Z_matrices.z_c;
	UINT inner_points = 1;
	printf("\nSimulation parameters for scattered field:"
		"\n\tNumber of grid vertices = %i"
		"\n\tMaterial parameter = %e"
		"\n\tc = %e"
		"\n\tdt = %e"
		"\n\tN_T = %i"
		"\n\tinner_points = %i"
		"\n\tLagrange_degree = %i\n\n",
		(int)rho.size(), material_param, c, dt, N_T, inner_points, Lagrange_degree);

	// Lagrange interpolators (temporal basis functions)
	CLagrange_interp timeBasis = CLagrange_interp(dt, Lagrange_degree);
	Z_matrices.timeBasis_D = timeBasis;
	CLagrange_interp timeBasis_Ns = timeBasis;
	timeBasis_Ns.diff();
	Z_matrices.timeBasis_Ns = timeBasis_Ns;

	Z_matrices.z_inner_points = inner_points;

	// do main computation
	cube S, D;
#ifdef OS_WIN
	clock_t t;
#else
	struct timeval * t = new struct timeval;
#endif
	start_timing(t);
	Z_matrices.compute_fields(S, D, rho);
	S *= material_param;
	finish_timing(t);

	start_timing(t);
	MATRIX rhs(D.n_rows, N_T, fill::zeros);
	VECTOR rhs_(D.n_rows, fill::zeros);
	printf("%s\n\n", "Marching on in time...");
	int j(0), k(0);
//#pragma omp parallel default(shared) private(j,k)
	for (j = 0; j < N_T; j++)
	{
//#pragma omp for
		for (k = 0; k < j+1; k++)
		{
			rhs_ += D.slice(k)*M.col(j - k) - S.slice(k)*J.col(j - k);
		}

		rhs.col(j) = rhs_;
		rhs_.zeros();

		//Status
		printf("\r%i ", j + 1);
		fflush(stdout);
	}

	finish_timing(t);

	// Output MAT file that stores the operators
	printf("Compressing matrices into Matlab form...");
	mat_t *matfpZ = NULL;
	matvar_t *matvar = NULL;

	// Save matrices as separate matlab variables
	if (CreateMatFile(&matfpZ, result_file) == -1)
	{
		return;
	}
	else
	{
		double NT = (double)N_T;
		InsertVar(&matfpZ, "N_T", &NT);
		InsertMatrix(&matfpZ, "E", rhs);
		FinishMatFile(&matfpZ);

		// free memory
		S.clear(), D.clear();

		printf("\t- done.\nOutput file location: %s\n\n", result_file);
	}
}
Ejemplo n.º 7
0
void run_Zmatrices_calculation(Zmatrices& Z_matrices, UINT Lagrange_degree,
	UINT outer_points, const char* result_file)
{
	// Simulation parameters
	double dt = Z_matrices.z_dt;
	double c = Z_matrices.z_c;
	UINT inner_points = outer_points + 1;
	UINT outer_points_sp = 5 * outer_points;
	UINT inner_points_sp = 5 * outer_points + 1;
	printf("\nSimulation parameters:"
		"\n\tc = %e"
		"\n\tdt = %e"
		"\n\tN_T = %i"
		"\n\touter_points = %i"
		"\n\tinner_points = %i"
		"\n\touter_points_sp = %i"
		"\n\tinner_points_sp = %i"
		"\n\tLagrange_degree = %i\n\n",
		c, dt, Z_matrices.z_N_T, outer_points, inner_points,
		outer_points_sp, inner_points_sp, Lagrange_degree);

	// Lagrange interpolators (temporal basis functions)
	CLagrange_interp timeBasis = CLagrange_interp(dt, Lagrange_degree);
	Z_matrices.timeBasis_D = timeBasis;
	CLagrange_interp timeBasis_Nh = timeBasis;
	timeBasis_Nh.integrate();
	Z_matrices.timeBasis_Nh = timeBasis_Nh;
	CLagrange_interp timeBasis_Ns = timeBasis;
	timeBasis_Ns.diff();
	Z_matrices.timeBasis_Ns = timeBasis_Ns;

	Z_matrices.z_outer_points_sp = outer_points_sp;
	Z_matrices.z_inner_points_sp = inner_points_sp;
	Z_matrices.z_outer_points = outer_points;
	Z_matrices.z_inner_points = inner_points;

	// do main computation and time
	cube S, D, Dp, Nh, Ns;
#ifdef OS_WIN
	clock_t t;
#else
	struct timeval * t = new struct timeval;
#endif
	start_timing(t);
	Z_matrices.compute(S, D, Dp, Nh, Ns);
	finish_timing(t);

	// Combine singular and hypersingular contributions of N operator
	cube N(Nh + Ns / (c*c));

	// Output MAT file that stores the operators
	printf("Compressing matrices into Matlab form...");
	mat_t *matfpZ = NULL;
	matvar_t *matvar = NULL;

	// Save matrices as separate matlab variables
	double NT = S.n_slices;
	if (CreateMatFile(&matfpZ, result_file) == -1)
	{
		return;
	}
	else
	{
		InsertVar(&matfpZ, "N_T", &NT);
		InsertCube(&matfpZ, "S", S);
		InsertCube(&matfpZ, "D", D);
		InsertCube(&matfpZ, "Dp", Dp);
		InsertCube(&matfpZ, "N", N);
		FinishMatFile(&matfpZ);

		// free memory
		S.clear(), D.clear(), Dp.clear(), Ns.clear(), Nh.clear();

		printf("\t - done. \nOutput file location: %s\n\n", result_file);
	}

}