Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 10 additions & 88 deletions glvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const char *gfunc_file = string_none;
const char *arg_keys = string_none;
int pad_digits = 6;
int gf_component = -1;
bool keep_attr = false;
int window_x = 0; // not a command line option
int window_y = 0; // not a command line option
int window_w = 400;
Expand Down Expand Up @@ -81,7 +80,6 @@ double scr_min_val, scr_max_val;

extern char **environ;

using StreamCollection = vector<unique_ptr<istream>>;

void PrintSampleUsage(ostream &out);

Expand All @@ -95,10 +93,7 @@ void SetGridFunction(StreamState& state);
void ReadParallel(int np, StreamState& state);

int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
const char *sol_prefix, StreamState& state,
int keep_attr);

int ReadInputStreams(StreamState& state, const StreamCollection& input_streams);
const char *sol_prefix, StreamState& state);

// Visualize the data in the global variables mesh, sol/grid_f, etc
// 0 - scalar data, 1 - vector data, 2 - mesh only, (-1) - unknown
Expand All @@ -121,7 +116,7 @@ bool GLVisInitVis(int field_type, StreamCollection input_streams)
if (input_streams.size() > 0)
{
GetAppWindow()->setOnKeyDown(SDLK_SPACE, ThreadsPauseFunc);
glvis_command = new GLVisCommand(&vs, stream_state, &keep_attr);
glvis_command = new GLVisCommand(&vs, stream_state, &stream_state.keep_attr);
comm_thread = new communication_thread(std::move(input_streams), glvis_command);
}

Expand Down Expand Up @@ -332,7 +327,7 @@ int ScriptReadParSolution(istream &scr, StreamState& state)
cout << "solution prefix: " << sol_prefix << endl;

err_read = ReadParMeshAndGridFunction(np, mesh_prefix.c_str(),
sol_prefix.c_str(), state, scr_keep_attr);
sol_prefix.c_str(), state);
if (!err_read)
{
state.Extrude1DMeshAndSolution();
Expand Down Expand Up @@ -1107,7 +1102,7 @@ void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient,
}
else
{
ReadInputStreams(new_session.state, input_streams);
new_session.state.ReadStreams(input_streams);
ofs.precision(8);
ofs << "solution\n";
new_session.state.mesh->Print(ofs);
Expand All @@ -1127,7 +1122,7 @@ void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient,
}
else
{
new_session.ft = ReadInputStreams(new_session.state, input_streams);
new_session.ft = new_session.state.ReadStreams(input_streams);
}
// Pass ownership of input streams into session object
new_session.input_streams = std::move(input_streams);
Expand Down Expand Up @@ -1182,7 +1177,7 @@ int main (int argc, char *argv[])
args.AddOption(&stream_state.fix_elem_orient, "-fo", "--fix-orientations",
"-no-fo", "--dont-fix-orientations",
"Attempt to fix the orientations of inverted elements.");
args.AddOption(&keep_attr, "-a", "--real-attributes",
args.AddOption(&stream_state.keep_attr, "-a", "--real-attributes",
"-ap", "--processor-attributes",
"When opening a parallel mesh, use the real mesh attributes"
" or replace them with the processor rank.");
Expand Down Expand Up @@ -1521,7 +1516,7 @@ void ReadParallel(int np, StreamState& state)
if (state.is_gf)
{
read_err = ReadParMeshAndGridFunction(np, mesh_file, sol_file,
state, keep_attr);
state);
if (!read_err)
{
SetGridFunction(state);
Expand All @@ -1530,7 +1525,7 @@ void ReadParallel(int np, StreamState& state)
else
{
read_err = ReadParMeshAndGridFunction(np, mesh_file, NULL,
state, keep_attr);
state);
if (!read_err)
{
state.SetMeshSolution();
Expand All @@ -1547,7 +1542,7 @@ void ReadParallel(int np, StreamState& state)

int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
const char *sol_prefix,
StreamState& state, int keep_attribs)
StreamState& state)
{
state.mesh = NULL;

Expand Down Expand Up @@ -1579,7 +1574,7 @@ int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,

mesh_array[p] = new Mesh(meshfile, 1, 0, state.fix_elem_orient);

if (!keep_attribs)
if (!state.keep_attr)
{
// set element and boundary attributes to be the processor number + 1
for (int i = 0; i < mesh_array[p]->GetNE(); i++)
Expand Down Expand Up @@ -1635,76 +1630,3 @@ int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,

return read_err;
}

int ReadInputStreams(StreamState& state, const StreamCollection& input_streams)
{
int nproc = input_streams.size();
Array<Mesh *> mesh_array(nproc);
Array<GridFunction *> gf_array(nproc);
string data_type;

int gf_count = 0;
int field_type = 0;

for (int p = 0; p < nproc; p++)
{
#ifdef GLVIS_DEBUG
cout << "connection[" << p << "]: reading initial data ... " << flush;
#endif
istream &isock = *input_streams[p];
// assuming the "parallel nproc p" part of the stream has been read
isock >> ws >> data_type >> ws; // "*_data" / "mesh" / "solution"
#ifdef GLVIS_DEBUG
cout << " type " << data_type << " ... " << flush;
#endif
mesh_array[p] = new Mesh(isock, 1, 0, state.fix_elem_orient);
if (!keep_attr)
{
// set element and boundary attributes to proc+1
for (int i = 0; i < mesh_array[p]->GetNE(); i++)
{
mesh_array[p]->GetElement(i)->SetAttribute(p+1);
}
for (int i = 0; i < mesh_array[p]->GetNBE(); i++)
{
mesh_array[p]->GetBdrElement(i)->SetAttribute(p+1);
}
}
gf_array[p] = NULL;
if (data_type != "mesh")
{
gf_array[p] = new GridFunction(mesh_array[p], isock);
gf_count++;
}
#ifdef GLVIS_DEBUG
cout << "done." << endl;
#endif
}

if (gf_count > 0 && gf_count != nproc)
{
mfem_error("Input streams contain a mixture of data types!");
}

state.mesh.reset(new Mesh(mesh_array, nproc));
if (gf_count == 0)
{
state.SetMeshSolution();
field_type = 2;
}
else
{
state.grid_f.reset(new GridFunction(state.mesh.get(), gf_array, nproc));
field_type = (state.grid_f->VectorDim() == 1) ? 0 : 1;
}

for (int p = 0; p < nproc; p++)
{
delete mesh_array[nproc-1-p];
delete gf_array[nproc-1-p];
}

state.Extrude1DMeshAndSolution();

return field_type;
}
Loading