8000 Drl4amr derefine by rw-anderson · Pull Request #2 · rw-anderson/mfem · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Drl4amr derefine #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: drl4amr
Choose a base branch
from
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
56 changes: 56 additions & 0 deletions mesh/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <cstring>
#include <ctime>
#include <functional>
#include <set>

// Include the METIS header, if using version 5. If using METIS 4, the needed
// declarations are inlined below, i.e. no header is needed.
Expand Down Expand Up @@ -6997,6 +6998,61 @@ bool Mesh::NonconformingDerefinement(Array<double> &elem_error,
return true;
}

bool Mesh::GeneralDerefinement(Array<int>& derefs)
{
MFEM_VERIFY(ncmesh, "Only supported for non-conforming meshes.");
MFEM_VERIFY(!NURBSext, "Derefinement of NURBS meshes is not supported. "
"Project the NURBS to Nodes first.");

DeleteLazyTables();

if (!derefs.Size()) { return false; }

const Table &dt = ncmesh->GetDerefinementTable();
Table dtT;
Transpose(dt, dtT);

// dt.Print();
// printf("dtT:\n");
// dtT.Print();

// Find the set of rows in the refinement table which correspond to
// the specified elements
std::set<int> set_rows;
for (int i = 0; i < derefs.Size(); i++) {
int el = derefs[i];
const int *row = dtT.GetRow(el);
set_rows.insert(row[0]);
}

Array<int> deref_rows;
std::set<int>::iterator it;
for (it = set_rows.begin(); it != set_rows.end(); ++it) {
deref_rows.Append(*it);
}

ncmesh->Derefine(deref_rows);

Mesh* mesh2 = new Mesh(*ncmesh);
ncmesh->OnMeshUpdated(mesh2);

Swap(*mesh2, false);
delete mesh2;

GenerateNCFaceInfo();

last_operation = Mesh::DEREFINE;
sequence++;

if (Nodes) // update/interpolate mesh curvature
{
Nodes->FESpace()->Update();
Nodes->Update();
}

return true;
}

bool Mesh::DerefineByError(Array<double> &elem_error, double threshold,
int nc_limit, int op)
{
Expand Down
3 changes: 3 additions & 0 deletions mesh/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@ class Mesh
bool RefineByError(const Vector &elem_error, double threshold,
int nonconforming = -1, int nc_limit = 0);

/** Derefine specified elements (and associated children as required) */
bool GeneralDerefinement(Array<int> &el);

/** Derefine the mesh based on an error measure associated with each
element. A derefinement is performed if the sum of errors of its fine
elements is smaller than 'threshold'. If 'nc_limit' > 0, derefinements
Expand Down
58 changes: 58 additions & 0 deletions miniapps/derefine-experiment/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "mfem.hpp"

#include <fstream>
#include <iostream>

using namespace std;
using namespace mfem;

const char *vishost = "localhost";
const int visport = 19916;
const int visw = 480;
const int vish = 480;
const int border = 15;
socketstream vis;
bool visualization = true;

void vismesh(Mesh* mesh)
{
if (visualization && vis.good())
{
vis.precision(8);
vis << "mesh" << endl << *mesh << flush;
vis << "window_title '" << "Mesh" << "'" << endl
<< "window_geometry "
<< (vish + border) << " " << 0
<< " " << visw << " " << vish << endl
<< "keys mgA" << endl;
}
}

int main(int argc, char *argv[])
{
vis.open(vishost, visport);

const char *mesh_file = "../../data/inline-quad.mesh";
// const char *mesh_file = "../../data/star.mesh";

Mesh *mesh = new Mesh(mesh_file, 1, 1);
mesh->EnsureNCMesh();

Array<Refinement> refs(2);
refs[0] = Refinement(0);
refs[1] = Refinement(5);
mesh->GeneralRefinement(refs, 1, 1);

// vismesh(mesh);

const Table &dt = mesh->ncmesh->GetDerefinementTable();
dt.Print();
Array<int> derefs(1);
derefs[0] = 3;

mesh->GeneralDerefinement(derefs);

vismesh(mesh);

return 0;
}
62 changes: 62 additions & 0 deletions miniapps/derefine-experiment/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at the
# Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights reserved.
# See file COPYRIGHT for details.
#
# This file is part of the MFEM library. For more information and source code
# availability see http://mfem.org.
#
# MFEM is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License (as published by the Free
# Software Foundation) version 2.1 dated February 1999.

# Use the MFEM build directory
MFEM_DIR ?= ../..
MFEM_BUILD_DIR ?= ../..
SRC = $(if $(MFEM_DIR:../..=),$(MFEM_DIR)/miniapps/derefine-experiment/,)
CONFIG_MK = $(MFEM_BUILD_DIR)/config/config.mk
# Use the MFEM install directory
# MFEM_INSTALL_DIR = ../../mfem
# CONFIG_MK = $(MFEM_INSTALL_DIR)/share/mfem/config.mk

MFEM_LIB_FILE = mfem_is_not_built
-include $(CONFIG_MK)

# Some choices below are based on the OS type:
NOTMAC := $(subst Darwin,,$(shell uname -s))
ifneq ($(NOTMAC),)
SOPREFIX = so
else
SOPREFIX = install_
endif

SEQ_MINIOBJS =
PAR_MINIOBJS =
ifeq ($(MFEM_USE_MPI),NO)
MINIOBJS = $(SEQ_MINIOBJS)
else
MINIOBJS = $(PAR_MINIOBJS) $(SEQ_MINIOBJS)
endif

.SUFFIXES:
.SUFFIXES: .o .cpp .mk
.PHONY: all cln clean clean-build clean-exec

# Remove built-in rule
%.o: %.cpp

# Replace the default implicit rule for *.cpp files
%.o: $(SRC)%.cpp $(SRC)%.hpp $(CONFIG_MK)
$(MFEM_CXX) -c -fPIC $(MFEM_FLAGS) $< -o $@

all: derefine-experiment

derefine-experiment: main.cpp
$(MFEM_CXX) $(MFEM_FLAGS) main.cpp -o derefine-experiment $(MFEM_LIBS)

# Generate an error message if the MFEM library is not built and exit
$(MFEM_LIB_FILE):
$(error The MFEM library is not built)

cln clean:
rm -f *.o *~
rm -rf *.dSYM *.TVD.*breakpoints $(SEQ_MINIOBJS) derefine-experiment
0