netgen/libsrc/visualization/importsolution.cpp

130 lines
3.0 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
//
// Read solution file
//
#include <mystdlib.h>
#include <myadt.hpp>
#include <linalg.hpp>
#include <csg.hpp>
#include <meshing.hpp>
2009-01-18 19:47:12 +05:00
#include <nginterface.h>
2009-01-13 04:40:13 +05:00
namespace netgen
{
2009-01-18 19:47:12 +05:00
2014-10-06 15:57:44 +06:00
extern shared_ptr<Mesh> mesh;
2009-01-13 04:40:13 +05:00
2015-10-19 13:08:30 +05:00
DLL_HEADER void ImportSolution2 (const char * filename)
2009-01-13 04:40:13 +05:00
{
ifstream inf (filename);
char buf[100], name[1000];
int i, size, comps, order;
bool iscomplex;
2019-08-06 17:16:13 +05:00
std::string type;
2009-01-13 04:40:13 +05:00
Flags flags;
while (1)
{
buf[0] = 0;
inf >> buf;
if (strcmp (buf, "solution") == 0)
{
inf >> name;
inf >> buf[0];
flags.DeleteFlags ();
while (buf[0] == '-')
{
inf >> buf[1];
inf.putback (buf[1]);
if (!isalpha (buf[1]))
{
break;
}
inf >> (buf+1);
flags.SetCommandLineFlag (buf);
buf[0] = 0;
inf >> buf[0];
}
inf.putback (buf[0]);
(*testout) << "Flags: " << endl;
flags.PrintFlags (*testout);
(*testout) << "done" << endl;
2014-10-06 15:57:44 +06:00
size = int(flags.GetNumFlag ("size", mesh->GetNP())); // Ng_GetNP()));
2009-01-13 04:40:13 +05:00
comps = int(flags.GetNumFlag ("components", 1));
type = flags.GetStringFlag ("type", "nodal");
order = int(flags.GetNumFlag ("order", 1));
iscomplex = flags.GetDefineFlag ("complex");
double * sol = new double[size*comps];
(*testout) << "import solution " << name << " size = " << size << " comps = " << comps << " order = " << order << endl;
for (i = 0; i < size*comps; i++)
{
inf >> sol[i];
// (*testout) << "sol: " << sol[i] << endl;
}
Ng_SolutionData soldata;
Ng_InitSolutionData (&soldata);
soldata.name = name;
soldata.data = sol;
soldata.dist = comps;
soldata.components = comps;
soldata.order = order;
soldata.iscomplex = iscomplex;
soldata.soltype = NG_SOLUTION_NODAL;
soldata.draw_surface = 1;
soldata.draw_volume = 1;
2019-08-06 17:16:13 +05:00
if (type == "element")
2009-01-13 04:40:13 +05:00
{
soldata.soltype = NG_SOLUTION_ELEMENT;
soldata.draw_surface = 0;
}
2019-08-06 17:16:13 +05:00
if (type == "surfaceelement")
2009-01-13 04:40:13 +05:00
{
soldata.soltype = NG_SOLUTION_SURFACE_ELEMENT;
soldata.draw_volume = 0;
}
2019-08-06 17:16:13 +05:00
if (type == "noncontinuous")
2009-01-13 04:40:13 +05:00
soldata.soltype = NG_SOLUTION_NONCONTINUOUS;
2019-08-06 17:16:13 +05:00
if (type == "surfacenoncontinuous")
2009-01-13 04:40:13 +05:00
soldata.soltype = NG_SOLUTION_SURFACE_NONCONTINUOUS;
Ng_SetSolutionData (&soldata);
}
else
{
// cout << "kw = (" << buf << ")" << endl;
(*testout) << "kw = (" << buf << ")" << endl;
break;
}
}
/*
struct Ng_SolutionData
{
char * name; // name of gridfunction
double * data; // solution values
int components; // used components in solution vector
int dist; // num of doubles per entry (alignment!)
Ng_SolutionType soltype; // type of solution function
};
// initialize solution data with default arguments
void Ng_InitSolutionData (Ng_SolutionData * soldata);
// set solution data
void Ng_SetSolutionData (Ng_SolutionData * soldata);
*/
}
}