Skip to content

Commit

Permalink
Port the solverdummy to the exceptions API
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonis committed Dec 14, 2024
1 parent 5fe8280 commit 2fcdeb0
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions examples/solverdummy/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use std::env;
use std::process::ExitCode;

fn main() -> ExitCode {
fn main() -> Result<ExitCode, precice::Error> {
let args: Vec<_> = env::args().collect();

if args.len() != 3 {
println!("The solverdummy was called with an incorrect number of arguments. Usage: ./solverdummy configFile solverName\n\n");
println!("Parameter description\n");
println!(" configurationFile: Path and filename of preCICE configuration\n");
println!(" solverName: SolverDummy participant name in preCICE configuration\n");
return ExitCode::from(1);
return Ok(ExitCode::from(1));
}

let config_file_name = &args[1];
let participant_name = &args[2];

println!("DUMMY: Running solver dummy with preCICE config file \"{}\" and participant name \"{}\".\n", config_file_name, participant_name);

let mut participant = precice::Participant::new(participant_name, config_file_name, 0, 1);
let mut participant = precice::Participant::new(participant_name, config_file_name, 0, 1)?;

assert!(participant_name == "SolverOne" || participant_name == "SolverTwo");

Expand All @@ -29,9 +29,9 @@ fn main() -> ExitCode {

const NUMBER_OF_VERTICES: usize = 3;

let dimensions = participant.get_mesh_dimensions(mesh_name) as usize;
let read_dimensions = participant.get_data_dimensions(mesh_name, read_data_name) as usize;
let write_dimensions = participant.get_data_dimensions(mesh_name, write_data_name) as usize;
let dimensions = participant.get_mesh_dimensions(mesh_name)? as usize;
let read_dimensions = participant.get_data_dimensions(mesh_name, read_data_name)? as usize;
let write_dimensions = participant.get_data_dimensions(mesh_name, write_data_name)? as usize;

let mut vertices = vec![0_f64; NUMBER_OF_VERTICES * dimensions];
let mut read_data = vec![0_f64; NUMBER_OF_VERTICES * read_dimensions];
Expand All @@ -49,39 +49,39 @@ fn main() -> ExitCode {

let vertex_ids: Vec<precice::VertexID> = {
let mut i32s = vec![0_i32; NUMBER_OF_VERTICES];
participant.set_mesh_vertices(mesh_name, &vertices, &mut i32s);
participant.set_mesh_vertices(mesh_name, &vertices, &mut i32s)?;
i32s
};

if participant.requires_initial_data() {
if participant.requires_initial_data()? {
println!("DUMMY: Writing initial data\n");
}

participant.initialize();
participant.initialize()?;

while participant.is_coupling_ongoing() {
if participant.requires_writing_checkpoint() {
while participant.is_coupling_ongoing()? {
if participant.requires_writing_checkpoint()? {
println!("DUMMY: Writing iteration checkpoint \n");
}

let dt = participant.get_max_time_step_size();
participant.read_data(mesh_name, read_data_name, &vertex_ids, dt, &mut read_data);
let dt = participant.get_max_time_step_size()?;
participant.read_data(mesh_name, read_data_name, &vertex_ids, dt, &mut read_data)?;

write_data = read_data.iter().map(|x| x + 1_f64).collect();

participant.write_data(mesh_name, write_data_name, &vertex_ids, &write_data);
participant.write_data(mesh_name, write_data_name, &vertex_ids, &write_data)?;

participant.advance(dt);
participant.advance(dt)?;

if participant.requires_reading_checkpoint() {
if participant.requires_reading_checkpoint()? {
println!("DUMMY: Reading iteration checkpoint \n");
} else {
println!("DUMMY: Advancing in time \n");
}
}

participant.finalize();
participant.finalize()?;
println!("DUMMY: Closing rust solver dummy... \n");

ExitCode::SUCCESS
Ok(ExitCode::SUCCESS)
}

0 comments on commit 2fcdeb0

Please sign in to comment.