Newer
Older
// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@geuz.org>.
//
// Contributor(s):
// Jonathan Lambrechts
//
#include <fstream>
#include <string>
#include "GmshConfig.h"
#include "Context.h"
#include "Field.h"
#include "GeoInterpolation.h"
#include "GModel.h"

Christophe Geuzaine
committed
#include "GmshMessage.h"
#include "Numeric.h"
#include "BackgroundMesh.h"
#include "OctreePost.h"
#include "PViewDataList.h"

Christophe Geuzaine
committed
#endif
Field::~Field()
{
for(std::map<std::string, FieldOption*>::iterator it = options.begin();
it != options.end(); ++it)
for(std::map<std::string, FieldCallback*>::iterator it = callbacks.begin();
it != callbacks.end(); ++it)
FieldOption *Field::getOption(const std::string optionName)
{
std::map<std::string, FieldOption*>::iterator it = options.find(optionName);
if (it == options.end()) {
Msg::Error("field option :%s does not exist", optionName.c_str());
return NULL;
}
return it->second;
}
for(std::map<int, Field *>::iterator it = begin(); it != end(); it++) {
Field *FieldManager::newField(int id, std::string type_name)
}
if(map_type_name.find(type_name) == map_type_name.end()) {
}
Field *f = (*map_type_name[type_name]) ();
if(!f)
int FieldManager::newId()
{
int i = 0;
iterator it = begin();
while(1) {
i++;
while(it != end() && it->first < i)
it++;
if(it == end() || it->first != i)
break;
}
return std::max(i, 1);
int FieldManager::maxId()
{
if(!empty())
return rbegin()->first;
else
return 0;
void FieldManager::deleteField(int id)
Msg::Error("Cannot delete field id %i, it does not exist", id);
class StructuredField : public Field

Jean-François Remacle
committed
{
double o[3], d[3];
int n[3];
double *data;
bool text_format, outside_value_set;
double outside_value;
public:
StructuredField()

Christophe Geuzaine
committed
options["FileName"] = new FieldOptionPath
(file_name, "Name of the input file", &update_needed);

Jean-François Remacle
committed
text_format = false;

Christophe Geuzaine
committed
options["TextFormat"] = new FieldOptionBool
(text_format, "True for ASCII input files, false for binary files (4 bite "
"signed integers for n, double precision floating points for v, D and O)",

Christophe Geuzaine
committed
&update_needed);
options["SetOutsideValue"] = new FieldOptionBool(outside_value_set, "True to use the \"OutsideValue\" option. If False, the last values of the grid are used.");
options["OutsideValue"] = new FieldOptionDouble(outside_value, "Value of the field outside the grid (only used if the \"SetOutsideValue\" option is true).");
std::string getDescription()

Christophe Geuzaine
committed
{
return "Linearly interpolate between data provided on a 3D rectangular "

Christophe Geuzaine
committed
"structured grid.\n\n"
"The format of the input file is:\n\n"
" Ox Oy Oz \n"
" Dx Dy Dz \n"
" nx ny nz \n"
" v(0,0,0) v(0,0,1) v(0,0,2) ... \n"
" v(0,1,0) v(0,1,1) v(0,1,2) ... \n"
" v(0,2,0) v(0,2,1) v(0,2,2) ... \n"
" ... ... ... \n"
" v(1,0,0) ... ... \n\n"
"where O are the coordinates of the first node, D are the distances "
"between nodes in each direction, n are the numbers of nodes in each "

Christophe Geuzaine
committed
"direction, and v are the values on each node.";

Christophe Geuzaine
committed
virtual ~StructuredField()
{
if(data) delete[]data;

Christophe Geuzaine
committed
double operator() (double x, double y, double z, GEntity *ge=0)
{
if(update_needed) {
error_status = false;
try {
std::ifstream input;
if(text_format)
input.open(file_name.c_str());
else
input.open(file_name.c_str(),std::ios::binary);
if(!input.is_open())
throw(1);
input.
exceptions(std::ifstream::eofbit | std::ifstream::failbit | std::
ifstream::badbit);

Jean-François Remacle
committed
if(!text_format) {
input.read((char *)o, 3 * sizeof(double));
input.read((char *)d, 3 * sizeof(double));
input.read((char *)n, 3 * sizeof(int));
int nt = n[0] * n[1] * n[2];
if(data)
delete[]data;
data = new double[nt];
input.read((char *)data, nt * sizeof(double));
}
else {
Loading
Loading full blame...