Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

Version 4.5.1 (development)
===========================

- Added a 'cutting_plane' script command to set the cutting plane orientation
(phi, theta in degrees), translation, kind, and algorithm in a single
command: 'cutting_plane <phi> <theta> <translation> [<kind> [<alg>]]'.
Expand All @@ -27,6 +28,11 @@ Version 4.5.1 (development)
They can only be issued after parallel streams have been initialized with
the 'parallel' command (if used).

- Added a script command 'pmesh <np> <mesh-prefix>' that loads a parallel mesh
without a solution. Like 'mesh', it captures reference nodes on the first load
and visualizes displacement on subsequent 'pmesh' loads.


Version 4.5 released on Feb 6, 2026
===================================

Expand Down
14 changes: 9 additions & 5 deletions lib/file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ int FileReader::ReadSerial(FileReader::FileType ft, const char *mesh_file,

data.SetMesh(new Mesh(meshin, 1, 0, data.fix_elem_orient));

if (ft == FileType::MESH)
if (ft == FileType::MESH || ft == FileType::MESH_ONLY)
{
data.SetMeshSolution();
if (ft == FileType::MESH) { data.SetMeshSolution(); }
}
else
{
Expand Down Expand Up @@ -114,7 +114,9 @@ int FileReader::ReadParallel(int np, FileType ft, const char *mesh_file,
switch (ft)
{
case FileType::MESH:
read_err = ReadParMeshAndGridFunction(np, mesh_file, NULL);
case FileType::MESH_ONLY:
read_err = ReadParMeshAndGridFunction(np, mesh_file, NULL, component,
ft == FileType::MESH);
break;
case FileType::GRID_FUNC:
read_err = ReadParMeshAndGridFunction(np, mesh_file, sol_file, component);
Expand Down Expand Up @@ -146,7 +148,9 @@ bool FileReader::CheckStreamIsComplex(std::istream &solin, bool parallel)
}

int FileReader::ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
const char *sol_prefix, int component)
const char *sol_prefix,
int component,
bool generate_mesh_solution)
{
data.SetMesh(NULL);

Expand Down Expand Up @@ -263,7 +267,7 @@ int FileReader::ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
data.SetGridFunction(gf_array, np, component);
}
}
else
else if (generate_mesh_solution)
{
data.SetMeshSolution();
}
Expand Down
4 changes: 3 additions & 1 deletion lib/file_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ class FileReader
static bool CheckStreamIsComplex(std::istream &sol, bool parallel = false);

int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
const char *sol_prefix, int component = -1);
const char *sol_prefix, int component = -1,
bool generate_mesh_solution = true);
int ReadParMeshAndQuadFunction(int np, const char *mesh_prefix,
const char *sol_prefix, int component = -1);

public:
enum class FileType
{
MESH,
MESH_ONLY, ///< Mesh geometry without a generated coloring grid function.
SCALAR_SOL,
VECTOR_SOL,
GRID_FUNC,
Expand Down
56 changes: 43 additions & 13 deletions lib/script_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ using namespace mfem;
enum class Command
{
Mesh,
ParMesh,
Solution,
ParSolution,
Quadrature,
Expand Down Expand Up @@ -95,6 +96,7 @@ static const ScriptCommands commands;
ScriptCommands::ScriptCommands()
{
(*this)[Command::Mesh] = {"mesh", "<file>", "Visualize the mesh."};
(*this)[Command::ParMesh] = {"pmesh", "<np> <mesh prefix>", "Visualize the distributed mesh."};
(*this)[Command::Solution] = {"solution", "<mesh> <solution>", "Visualize the solution."};
(*this)[Command::ParSolution] = {"psolution", "<np> <mesh prefix> <keep attributes> <solution prefix>", "Visualize the distributed solution."};
(*this)[Command::Quadrature] = {"quadrature", "<mesh> <quadrature>", "Visualize the quadrature."};
Expand Down Expand Up @@ -256,24 +258,46 @@ int ScriptController::ScriptReadParQuadrature(istream &scr, DataState &state)
return err_read;
}

int ScriptController::ScriptReadDisplMesh(istream &scr, DataState &state)
int ScriptController::ScriptReadDisplMesh(istream &scr, DataState &state,
bool parallel)
{
DataState meshstate;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be also cloned to preserve all settings (current or future). I opened a new PR fixing all occurrences #384 😉 .

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you fixed it in the other PR, do you still want me to fix it here?

string word;
int np = 1;

cout << "Script: mesh: " << flush;
scr >> ws >> word;
cout << "Script: " << (parallel ? "pmesh" : "mesh") << ": " << flush;
if (parallel)
{
named_ifgzstream imesh(word.c_str());
if (!imesh)
if (!(scr >> np))
{
cout << "Can not open mesh file: " << word << endl;
cout << "Error reading the number of processors." << endl;
return 1;
}
cout << word << endl;
meshstate.SetMesh(new Mesh(imesh, 1, 0, state.fix_elem_orient));
if (np <= 0)
{
cout << "Invalid number of processors: " << np << endl;
return 1;
}
cout << "# processors: " << np << "; " << flush;
}
meshstate.ExtrudeMeshAndSolution();
if (!(scr >> ws >> word))
{
cout << "Error reading the mesh " << (parallel ? "prefix" : "filename")
<< endl;
return 1;
}
cout << word << endl;

meshstate.keep_attr = state.keep_attr;
meshstate.fix_elem_orient = state.fix_elem_orient;
FileReader reader(meshstate);
int read_err = parallel ?
reader.ReadParallel(np, FileReader::FileType::MESH_ONLY,
word.c_str(), NULL) :
reader.ReadSerial(FileReader::FileType::MESH_ONLY,
word.c_str(), NULL);
if (read_err) { return read_err; }

Mesh* const m = meshstate.mesh.get();
if (init_nodes == NULL)
{
Expand Down Expand Up @@ -420,6 +444,7 @@ bool ScriptController::ExecuteScriptCommand()
switch (cmd)
{
case Command::Mesh:
case Command::ParMesh:
case Command::Solution:
case Command::ParSolution:
case Command::Quadrature:
Expand All @@ -428,7 +453,7 @@ bool ScriptController::ExecuteScriptCommand()
case Command::DataCollField:
case Command::DataCollQuad:
{
DataState new_state;
DataState new_state = win.data_state.CloneEmpty();

switch (cmd)
{
Expand All @@ -447,14 +472,17 @@ bool ScriptController::ExecuteScriptCommand()
}
break;
case Command::Mesh:
if (ScriptReadDisplMesh(scr, new_state))
case Command::ParMesh:
if (ScriptReadDisplMesh(scr, new_state,
cmd == Command::ParMesh))
{
done_one_command = 1;
continue;
}
if (new_state.mesh == NULL)
{
cout << "Script: unexpected 'mesh' command!" << endl;
cout << "Script: unexpected '" << word << "' command!"
<< endl;
done_one_command = 1;
continue;
}
Expand Down Expand Up @@ -1019,7 +1047,9 @@ void ScriptController::PlayScript(Window win, istream &scr)
done = true; // start the visualization
break;
case Command::Mesh:
if (script.ScriptReadDisplMesh(scr, script.win.data_state))
case Command::ParMesh:
if (script.ScriptReadDisplMesh(scr, script.win.data_state,
cmd == Command::ParMesh))
{
return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/script_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class ScriptController
static int ScriptReadQuadrature(std::istream &scr, DataState &state);
static int ScriptReadParSolution(std::istream &scr, DataState &state);
static int ScriptReadParQuadrature(std::istream &scr, DataState &state);
int ScriptReadDisplMesh(std::istream &scr, DataState &state);
int ScriptReadDisplMesh(std::istream &scr, DataState &state,
bool parallel = false);
int ScriptReadDataColl(std::istream &scr, DataState &state,
bool mesh_only = true, bool quad = false);

Expand Down
Loading