Page MenuHomec4science

field.h
No OneTemporary

File Metadata

Created
Thu, Sep 5, 20:21
/*
Copyright 2008 Guillaume ANCIAUX (guillaume.anciaux@epfl.ch)
This file is part of ParaViewHelper.
ParaViewHelper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ParaViewHelper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ParaViewHelper. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FIELD_H
#define FIELD_H
#include "common.h"
#define INTEGER 0
#define DOUBLE 1
class Field {
public:
Field(int type){
this->data_double = NULL;
this->data_integer = NULL;
dim = 0;
nb_dof = 0;
this->type = type;
scale_factor = 1;
flag_embedded_dimension = 0;
};
Field(double * data,int dimension, int n_elem){
this->data_double = data;
dim = dimension;
nb_dof = n_elem;
type = DOUBLE;
scale_factor = 1;
flag_embedded_dimension = 0;
};
Field(int * data,int dimension, int n_elem){
this->data_integer = data;
dim = dimension;
nb_dof = n_elem;
type = INTEGER;
scale_factor = 1;
flag_embedded_dimension = 0;
};
double * GetDData(){
if (type != DOUBLE)
FATAL("Field is not storing double data");
return data_double;
};
int * GetIData(){
if (type != INTEGER)
FATAL("Field is not storing integer data");
return data_integer;
};
void AllocateData(){
if (dim == 0 || nb_dof == 0) FATAL("size not set yet : can,not allocate");
if (type == DOUBLE){
if (data_double != NULL) FATAL("cannot reallocate, one array is already present");
data_double = (double*)malloc(sizeof(double)*dim*nb_dof);
}
if (type == INTEGER) {
if (data_integer != NULL) FATAL("cannot reallocate, one array is already present");
data_integer = (int*)malloc(sizeof(int)*dim*nb_dof);
}
};
char name[256];
unsigned int dim;
unsigned nb_dof;
double scale_factor;
double * data_double;
int * data_integer;
int type;
int flag_embedded_dimension;
};
#endif

Event Timeline